How to insert variables values into html input text fields?

时间:2016-01-06 10:36:05

标签: php html

is there a way in Php to modify the value of a html input text field dynamic? I want to display data from db an thought input text fields would be the best way.

F.e. I get an array from a soap server and want to put the values into different text input fields, how can I do this? Do I have to create a complete new site or can I dynamically insert the values to fields on the same site?

Regards Ismir

2 个答案:

答案 0 :(得分:1)

如果您的数据位于var template = '{{#data}} <td> Team: {{teamName}} </td> {{/data}}'; var output = Mustache.to_html(template, {data:standings.standing}); ,您可以立即使用它来创建HTML输出。

您的HTML可能如下所示:

array $arr

如果您的HTML已经在屏幕上,并且您希望使用新值<input type="text" name="firstname" value="<?php echo $arr['firstname']; ?>"> 更新屏幕,则必须使用AJAX / javascript / jQuery。

答案 1 :(得分:0)

以上所有答案都很好,但为了防止出现警告,您必须将其括在一个isset()中。

<input type="text" name="firstname" value="<?php if(isset($arr['firstname'])){echo $arr['firstname'];}else{echo '';} ?>">

或使用下面的短代码:

<input type="text" name="firstname" value="<?php echo isset($arr['firstname']) ? $arr['firstname'] : ''; ?>">