将值插入php文件中的输入标记

时间:2012-10-02 07:13:37

标签: android

如何在php文件的输入框中插入一个值?

例如我有这个代码

<h1><a>App Test Form</a></h1>
        <form id="form_6" class="digitalfuture"  method="post" action="#main_body">
                    <div class="form_description">
            <h2>App Test Form</h2>
            <p></p>
        </div>                      
            <ul >

                    <li id="li_8" >
        <label class="description">Name <span id="required_8" class="required">*</span></label>
        <span>
            <input id="element_8_1" name= "element_8_1" class="element text" maxlength="255" size="8" value="hello" />
            <label>First</label>
        </span>
        <span>
            <input id="element_8_2" name= "element_8_2" class="element text" maxlength="255" size="14" value="" />
            <label>Last</label>
        </span><p class="guidelines" id="guide_8"><small>Please tell us your name</small></p> 
        </li>

任何人都可以指出任何可以帮助我的教程吗?

1 个答案:

答案 0 :(得分:0)

source.php:

<?php
    $data = 'text';
?>

input.php:

<?php
    include('source.php');
    echo '<input type="text" name="example" value="', $data, '" />';
?>

这会将$ data的内容插入到输入字段值中。

或者你的意思是其他什么?

如果您希望在打开页面时直接显示文本,可以在输入标记中使用html5功能“占位符”。像这样:

<input type="text" name="example" placeholder="Write your comment" />

这将在页面中显示一个输入字段,文字“写你的评论”在字段中可见,直到用户点击它和/或写入字段(无需手动删除占位符文本,它会自动消失)。

所以当你把它们组合起来时,它会是这样的:

source.php:

<?php
    $data = 'text';
?>

input.php:

<?php
    include('source.php');
    echo '<input type="text" name="example" placeholder="', $data, '" />';
?>