Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Approve first when submit the form

I'm using the PHP CodeIgniter framework.

The problem is that I want the user to check those fields that they have entered and approved by selecting checkbox then submitting the form.

Like these are the fields.

<tr>    
    <td>Remarks </td>
    <td><textarea name="particular" rows="3" class="save_record autosuggestship"></textarea></td>   
    <td>&nbsp;</td>
    <td>&nbsp;</td>                 
</tr>
<tr>
    <td>Custom Reference No.</td>
    <td><input type = 'text' name = 'custom_ref_no' class = 'save_record autosuggestship' id="custom_ref_no" /></td>
    <td>Date</td>
    <td><input name = 'costom_date' type = 'text' class = 'save_record date_class autosuggestship' id="costom_date" /></td>
</tr>
<tr>
    <td>
        <p> Container Information </p>
    </td>
    <td>

And this the Checkbox to approve.

<tr>
    <td>Approve</td>
    <td><input type="checkbox" id="Approve" /></td>
    <td>&nbsp;</td>
    <td align="left">&nbsp;</td>
</tr>
like image 724
Abdul Salam Avatar asked Nov 04 '22 00:11

Abdul Salam


1 Answers

Uses jQuery: try inserting this in your page wrapped in <script></script> tags and including jQuery.

$(document).ready(function() {
    $('form input[type=submit]').on('click', function(e) {
      e.preventDefault();
      if($('#Approve').attr('checked') == 'checked') {
        $('form').submit();
      }
      else {
        alert('You must check the Approve checkbox to continue!');
      }
    });
    // if the user presses enter.
    $('form').on('keyup', function(e) {
      if(e.which == 13) {
       $('form').submit();
      }
    });
});

In PHP (make sure you give your input a name="Approve":

if(isset($_POST['Approve']) {
  // they have ticked the checkbox.
}
like image 159
Tom Hallam Avatar answered Nov 10 '22 00:11

Tom Hallam