dongxinjun3944 2015-12-10 22:50
浏览 81
已采纳

单击按钮调用PHP函数[复制]

This question already has an answer here:

This is the PHP function, it is messy right now (redundant lines) that I will clean up after. I am stuck right now, really trying to keep the whole process to one page:

<?php function signpetitiion() {
$API_KEY = 'MYAPIKEY';
$REQUEST_URL = 'https://api.change.org/v1/petitions/get_id';
$PETITION_URL = 'https://www.change.org/p/URLTOMYPETITION';
$parameters = array(
  'api_key' => $API_KEY,
  'petition_url' => $PETITION_URL

}


?>

So this doesn't work because it is browser side:

<form onsubmit="sign_petitiion()">

How do I get this function to run with a button click? Should I convert to a JS script? if so how?

Or call with AJAX? if so how?

if(isset($_POST['go'])){

    <input type="submit" name="go" method="post">

Question closed as I was typing my answer

I know this question (in different ways) has been asked before, I had read through them but the answers were either too complicated for me (NEWB) or just a comment saying you can't.

Any ways I have found my answer,

I had to change these 2 lines

function sign_petitiion() {

to

     if(isset($_POST['go'])){

and then

<form onsubmit="sign_petitiion()">

to

    <form method="Post" class="sign" action="mypage.php">
</div>
  • 写回答

1条回答 默认 最新

  • dtj2ww9500 2015-12-10 22:54
    关注
    <!-- HTML-->
    <a href='index.php?run=true'>Execute it </a>
    
    //*.php
    if($_Get['true']){
        signpetitiion();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误