使用$ _GET数据自动填充插入表单

时间:2013-02-12 13:24:02

标签: php html cakephp-1.2

我有一个搜索表单,用户可以在同一个字段中插入一个或多个作者的名字。
我有这个代码:

Author<br /><input type="text" name="autore" value=<?php echo $_GET['autore'] ?> ><br/>

自动填写下一页的“作者”字段。

我的问题是,如果用户写了例如:

san, gli, tro

在作者领域,我只会得到'san',而我想要'san,gli,tro'。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

如果您这样做会发生什么:

Author<br /><input type="text" name="autore" value="<?php echo $_GET['autore'] ?>" ><br/>

(注意属性周围的引号)

答案 1 :(得分:0)

你需要在php中加上值的引号。像这样:

Author<br /><input type="text" name="autore" value="<?php echo $_GET['autore'] ?>" ><br/>

在你的情况下,最终的HTML将是

Author<br /><input type="text" name="autore" value=san gli tro ><br/>

因此,属性value的值为san,另一个为空属性名称。

使用引号,最终的html将是

Author<br /><input type="text" name="autore" value="san, gli, tro" ><br/>

您需要的是什么。

相关问题