0

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.

It was working when I use html, but when I add in the php it doesn't work. I think it is because I am not calling selectbasic but I don't know where to add the 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

    <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>      
4
  • 1
    Show us the HTML after the PHP has been processed. Commented Mar 19, 2014 at 17:54
  • I presume you have a submitForm function? If not, remove onsubmit="submitForm" onreset="" --- Plus, change <button type="submit2" to <button type="submit" Commented Mar 19, 2014 at 17:56
  • You should handle that logic in php and not change the action attribute in javascript based on a form variable. Commented Mar 19, 2014 at 17:56
  • Do you really have all those spaces in class="btn btn- success"? Commented Mar 19, 2014 at 17:58

3 Answers 3

2

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".

Sign up to request clarification or add additional context in comments.

Comments

0

Try ...action="POST"... for your action attribute. That specifies the type of form submission rather than any function to call prior to sending the form.

Comments

0

You can remove onrest from your form element.

If you want form reset functionality, you can add an input with the parameter type="reset".

I also suggest you rename submit2 to submit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.