简体   繁体   English

单击时PHP获取按钮$ _POST的值

[英]PHP Get button $_POST value when clicked

OK I might be a bit out of my depth here I have a page like this: 好吧,我在这里可能有点儿不明白,我有这样的页面:

在此处输入图片说明

Now When Someone clicks the button a fancy sliding page "slides" over the current page, asking for the user to enter his application details. 现在,当某人单击该按钮时,一个漂亮的滑动页面会在当前页面上“滑动”,要求用户输入其应用程序详细信息。

在此处输入图片说明

Now I need to get the clicked Button's value which contains the jobID primary key inorder for me to process the application data...makes sense? 现在,我需要获取包含jobID主键的单击按钮的值,以便我处理应用程序数据...有意义吗?

What I would like to know is, since no actual page is loaded and no data gets send , (its only css & jquery providing a "modal" for the application page). 我想知道的是, 由于没有实际的页面被加载,也没有数据被发送 ,(它只有css和jquery为应用程序页面提供“模式”)。

How would I go about finding the value of button. 我将如何寻找按钮的价值。 Im not sure where to start really? 我不确定从哪里开始呢?

  1. Is it possible getting it with PHP alone? 可以单独使用PHP获得它吗? (again keeping in mind no actual data gets send)? (再次牢记没有发送任何实际数据)?
  2. Can the value be retrieved with AJAX? 可以使用AJAX检索值吗?
  3. Would it require some sort of completely different language like node.js or similar? 是否需要某种完全不同的语言,例如node.js或类似语言?

Any tips / advice / references appreciated 任何提示/建议/参考赞赏

This ajax example help you you get your click value you have to set onclick button attribute in your html. 这个ajax示例可帮助您获取点击值,您必须在html中设置onclick按钮属性。

<script type="text/javascript">

  function loadajax(value){
      if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
      } else {
          // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      var pid = value;
      alert(pid);
      var queryString = "?send your primary key id or jobid=" + pid;
      xmlhttp.open("POST","Page name" + queryString,true);
      xmlhttp.send();
    }

</script>
  1. Yes. 是。 PHP can return to you only a JSON data PHP只能向您返回JSON数据
  2. Yes, You can do AJAX 是的,您可以执行AJAX
  3. No. PHP, HTML, CSS, JavaScript are enough. 不需要。PHP,HTML,CSS,JavaScript就足够了。 Maybe you can use Bootstrap css framework and JQUERY I recommend: You can use html decoration. 也许您可以使用Bootstrap CSS框架JQUERY,我建议:您可以使用html装饰。 Its mean: to define your own HTML attributes. 它的意思是:定义自己的HTML属性。 Example: 例:

    <a class="view" href="javascript:;" <a class =“ view” href =“ javascript :;” data-id="111" >VIEW</a> data-id =“ 111” > VIEW </a>

Javascript code: JavaScript代码:

<script language="JavaScript">
     $("a.view").click(function(){
            var jobId = $(this).attr("data-id");
            $.ajax({
                url: "[YOUR_URL]",
                data:{"job_id":jobId},
                type:"post", 
                success:function(response){
                    //You must open your css modal window and fill
                } 
            })
     }); 
</script>

PHP code: PHP代码:

<?php
header('Content-Type: application/json; charset=utf-8');
$responseData = []; // you fill this variable with response data
echo json_encode($responseData);

For your apply button , have an onclick registered to some function in javascript along with the event passed in the given manner : 对于您的Apply按钮,将onclick与以指定方式传递的事件一起注册到javascript中的某些函数:

<button value="(whatever)" onclick ="sendreq(event)" >

Now in your javascript , have a function sendreq(e) : 现在在您的javascript中,具有一个函数sendreq(e):

 function sendreq(e)
 {
   var jobId = e.target.value;
   //Process your data however with this jobId you have
   //Make XMLHttpRequest() and open a post ajax call of your choosing.

 } 

The variable jobId will contain what you require . 变量jobId将包含您需要的内容。

1st you can not show the module where you set jobID . 首先,您无法显示在其中设置jobID的模块。

If you want to get directly JobID then try '$_POST[]' method in URL itself like http://yourURL.Domain/?id= 'jobId' and it will directly move or use for next page as well as current page also. 如果您想直接获取JobID,则尝试在URL本身中使用“ $ _POST []”方法,例如http://yourURL.Domain/?id = 'jobId' ,它将直接移动或用于下一页以及当前页面。 . .

But in that way JobID will show in URL. 但是通过这种方式JobID将显示在URL中。 :( :(

if You want to go on AJAX then it is better. 如果您想使用AJAX,那就更好了。 . .

otherwise try html+php I hope that is useful . 否则尝试html + php,我希望这是有用的。 . .

<!-- this is Simple code for idea what i say. . .-->
  <html>
    <body>
     <form action="#" method="post">
       <input type = "XYZ" id="JobID">
       <input type = "Submit" value="submit">
      </form>
    </body>
  </html>

   <?php 
        if(isset($_POST['JobID']))
         //USE JobID 
    ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM