如何从提交的onclick事件调用php函数 [英] how to call a php function from onclick event of submit

查看:650
本文介绍了如何从提交的onclick事件调用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试下一个方式



i've trying of the next way

 <?php  <br mode="hold" /?> function myfnc()
{   
echo "Hello world" ;   
}  
?>  
<form action="trytocallfunction.php" method="post">
<input type="submit" name="submit" value="submit"  önclick="<?php myfnc();??>" />
</form>

推荐答案

myfnc()存在于服务器端,仅在服务器端执行,它不会出现在客户端,你必须将表单提交给服务器并在那里调用该函数,试试这个:

The myfnc() exists on the server-side and is to be executed on the server-side only, it will not appear on the client-side, you have to submit the form to the server and call the function over there, try this:
<?php

if (isset(


_POST ['submit']))

{

myfnc();

}

function myfnc()

{

echo Hello world ;

}

>
< 形式 <跨度class =code-attribute> action = trytocallfunction.php method = 发布 >
< 输入 type = 提交 name = submit value = 提交 >
< / form >
_POST['submit'])) { myfnc(); } function myfnc() { echo "Hello world" ; } ?> <form action="trytocallfunction.php" method="post"> <input type="submit" name="submit" value="submit"> </form>



你应该读到这个了解更多 HTML5初学者指南& CSS3 - 服务器端故事 [ ^ ]


这篇关于如何从提交的onclick事件调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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