Gio*_*Gio 2 html php forms function
我想写一个php页面,其中有一个html表单.我想将我的表单的所有输入(例如数字)发送到php函数(而不是javascript函数;我使其隐藏我的javascript函数代码).
如何将输入值发送到php函数?
可以通过调用php函数onclick="function(param1, param2)"吗?
我知道javascript是一种客户端语言,而php是服务器端语言.
如果可能,如何在输入字段中写入函数的返回值?
我想留在我的页面中.
这是对的 - action="#"?
我的代码是:
<form action="#" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>
<?php echo "ciaoooo"; ?>
<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>
<br></br>
<input type="submit" value="send"></input>
</form>
Run Code Online (Sandbox Code Playgroud)
帮助我实现简单的php函数以及从输入到函数的值的传递!谢谢!
让你action空虚.您不需要设置 onclick属性,这只是javascript.当您单击提交按钮时,它将使用表单中的输入重新加载您的页面.所以在表单顶部编写PHP代码.
<?php
if( isset($_GET['submit']) )
{
//be sure to validate and clean your variables
$val1 = htmlentities($_GET['val1']);
$val2 = htmlentities($_GET['val2']);
//then you can use them in a PHP function.
$result = myFunction($val1, $val2);
}
?>
<?php if( isset($result) ) echo $result; //print the result above the form ?>
<form action="" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>
<?php echo "ciaoooo"; ?>
<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>
<br></br>
<input type="submit" name="submit" value="send"></input>
</form>
Run Code Online (Sandbox Code Playgroud)