从提交按钮调用php函数 [英] calling php function from submit button
本文介绍了从提交按钮调用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将输入字段地址
的值传递给php。所以,当我点击提交按钮,它将存储在PHP中。
I want to pass the value of input field address
to php. So that when i click on submit button it will be store in php.
<input type="text" name="address">
<input type="submit" name="go" method="post">
<?php
if($_POST){
if(isset($_POST['go'])){
call();
}else{
echo "Error";
}
}
function call(){
echo "hi";
print(document.address.value);
}
?>
然而,当我点击按钮时,它没有任何反应。
However when i click on button it response nothing.
推荐答案
您正在混合使用PHP和JavaScript。如果你想要一个纯粹的PHP解决方案,你可以这样做:
You are mixing PHP and JavaScript. If you want a pure PHP solution you could do something like:
<?php
if(isset($_POST['go'])){
$address = $_POST['address'];
echo $address;
}
?>
<form method="POST">
<input type="text" name="address">
<input type="submit" name="go" method="post">
</form>
在PHP提交表单后,您可以使用 $ _ POST来访问表单值
所以使用 $ _ POST ['address']
而不是 document.address.value
With PHP once the form is submitted you can access form values with $_POST
so use $_POST['address']
instead of document.address.value
这篇关于从提交按钮调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文