我想将输入字段 address
的值传递给 php。这样当我点击提交按钮时,它将存储在 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);
}
?>
但是,当我点击按钮时,它没有任何反应。
最佳答案
您正在混合使用 PHP 和 JavaScript。如果你想要一个纯 PHP 解决方案,你可以这样做:
<?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。值
关于php - 从提交按钮调用 php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30340754/