你能用PHP设置一个表单字段值吗? [英] Can you set a form field value with PHP?

查看:109
本文介绍了你能用PHP设置一个表单字段值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用$ _GET函数从url(http:.... / index.html?variable = value)中抽取一个值,这是基本的东西。但是,我需要在表单中使用该值。



通常,我会设置

 <?php echo'value ='。$ variable。''; ?> 

或类似的东西。但是,我不能在我的表单中使用我正在使用的编辑器中的PHP。



我可以在表单中设置一个值而不使用我的表单中的PHP吗?如果是这样,怎么做?



编辑:
使用CMS编辑器我使用的是不能将php代码存储到服务器。 (我正在使用FCKeditor,和Dubral一样)。这是所有CMS使用Wordpress的安全措施。基本上我想发送/设置值的形式与PHP。与javascript相似:document.form.field.value

解决方案

设置默认值的最佳方法现有值)在你的问题中提到 value ='。$ variable。''



如果您不能使用这种标记,那么您可以使用javascript(无论是使用AJAX引用辅助文件/提要,还是使用相同的变量回显技术),以便在特定字段中替换后的值



$ p $ < script type = 文本/ JavaScript的 >
document.form [0] .name.value =<?php echo $ name;?>;
< / script>


I use the $_GET function to pull a value with php from the url (http:..../index.html?variable=value), basic stuff. However, I need to use that value in my form.

Typically, I would set

<?php echo 'value="'.$variable.'"' ; ?>

or something to that effect. However, I can't use php inside my form using the editor I'm working with.

Can I set a value in the form without using PHP in my form? If so, how?

Edit: with the CMS editor I'm using you can't store php code to the server. (I'm using FCKeditor. The same used by Dubral). This is a security measure all CMS's use even Wordpress. Basically I want to send/set the value in the form with php. Similar to how javascript does it: document.form.field.value

解决方案

The best way to set default values (ie pre-existing values) within an HTML form is as you mentioned in your question value="'.$variable.'"'.

If you are unable to use markup like that, then you may be able to use javascript (whether referencing a secondary file/feed using AJAX, or using the same variable echoing technique) to replace the values in the specific fields after the page has loaded.

ie

<script type="text/javascript">
document.form[0].name.value = "<?php echo $name; ?>";
</script>

这篇关于你能用PHP设置一个表单字段值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆