简体   繁体   English

提交按钮不能在php中工作

[英]Submit button not working in php

I have a form and the submit button is not working. 我有一个表单,提交按钮不起作用。 Submit is based on whether someone approves or denies. 提交是基于某人是否批准或拒绝。 Also approve deny dropdown needs to pre-populate if someone goes back to tha page by using a temp id from what they entered. 如果有人通过使用他们输入的临时ID返回到页面,也批准拒绝下拉需要预先填充。

It was working when I use html, but when I add in the php it doesn't work. 当我使用html时,它正在工作,但是当我添加php时它不起作用。 I think it is because I am not calling selectbasic but I don't know where to add the id. 我认为这是因为我没有调用selectbasic但我不知道在哪里添加id。 I have tried different variations and can't get it to work. 我尝试了不同的变化,但无法使其发挥作用。

  <form name="iform" id="myform" method="post" onsubmit="submitForm" onreset=""  enctype="multipart/form-data" action="submitForm" class="iform">

      <label for="Email">Email Address for Officer:</label>
      <input class="itext" type="text" value="<?php print $jsonData['Email']; ?>" name="Email" id="Email" />
      <br /><br />

      <label for="ApproveDeny">Approve or Deny Warrant:</label>
      <select class="iselect" name="selectbasic" id="selectbasic">
      <?php
         $values = array("1" => "Choose an option", "2" => "Approved", "3" => "Denied");
         foreach ($values as $value) {
           $selectString = '';
           if ($value == $jsonData['selectbasic']) {
               $selectString = ' selected';
           }
           print '<option value="' . $value . '"' . $selectString . '>' . $value . '</option>';
         }
      ?>                         
      </select>
      <br /><br />

      <label>&nbsp;</label><button type="submit2" class="btn btn-success">submit</button>
       <input type="hidden" name="tempId" id="tempId" value="<?php print $tempId; ?>" />

  </form>

javascript JavaScript的

    <script type="text/javascript">
    document.getElementById('selectbasic').onchange = function(){

    if (this.value=="2") {
    newAction='html_form_judge.php';
} else if (this.value=="3") {
    newAction='html_form_judgedeny.php';
} else {
    newAction='else.php';
}
     document.getElementById('myform').action = newAction;
   }
       </script>      

You're setting the value of each option to the name, not numerical key, of each element in your array. 您要将每个选项的值设置为数组中每个元素的名称,而不是数字键。 Do it like this: 像这样做:

foreach ($values as $id => $value) {
    ...
    print '<option value="' . $id . '"' . $selectString . '>' . $value . '</option>';
}

That way, in your javascript, the selected value might actually equal "2" rather than "Approved". 这样,在您的javascript中,所选值实际上可能等于“2”而不是“已批准”。

Try ...action="POST"... for your action attribute. 尝试... action =“POST”...为您的操作属性。 That specifies the type of form submission rather than any function to call prior to sending the form. 这指定了表单提交的类型,而不是在发送表单之前调用的任何函数。

You can remove onrest from your form element. 您可以从表单元素中删除onrest

If you want form reset functionality, you can add an input with the parameter type="reset" . 如果需要表单重置功能,可以使用参数type="reset"添加输入。

I also suggest you rename submit2 to submit . 我还建议你重命名submit2submit

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

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