1

I have form and in the form I have a mobile number input field and I want to assign that mobile number value to PHP variable on form submit handler. Currently, the mobile value holds in temp_mob variable like var temp_mob = $('#mobile').val(); I want assign temp_mob value to php variable $phone_number

My Code:

<form class="well form-horizontal"  method="post"  id="contact_form">
  <fieldset>
    <legend><center><h2><b style="color: #fff">Registration Form</b></h2></center></legend><br>
    <div class="form-group">
      <label class="col-md-4 pd-r control-label">firstname</label>  
      <input  name="first_name" id="first_name" class="form-control tboxs"  type="text">
    </div>
    <div class="form-group">
      <label class="col-md-4 pd-r control-label">Phone Number</label>  
        <div class="input-group">
         <input name="mobile" id="mobile" placeholder="+91" class="form-control tboxs" type="text">
      </div>
    </div>
    <div class="form-group" style="text-align: center!important;">
      <label class="col-md-4 pd-r control-label"></label>
      <div class="col-md-4 pd-r"><br>
        <button style="width: 100%"  type="submit"  value="submit" class="btn-theme-colored btn ">SUBMIT <span class="glyphicon glyphicon-send"></span></button>
      </div>
    </div>
  </fieldset>
</form>

Script:

<script>
  $("#contact_form").validate(
    {
    rules:{
      "first_name":{
    required: true,
    },
     "mobile":{
    required: true,
    },
     },
  messages:{
    "first_name":{
    required: "The name field is mandatory!",
    },
      "mobile":{
    required: "The phonenumber is required!",
    },
  },
  submitHandler: function(form) {
     var temp_mob = $('#mobile').val();

    <?php
      $otp = random_string('numeric',4);
      $time =  date('Y-m-d H:i:s');
      $newOTP= $otp;
      $this->session->set_tempdata('otp', $newOTP,300);
      $data = array(
        'number'=> $phone_number,
        'current_time_stamp' =>$time,
        'otp' =>$newOTP,
      );
      ?>
     }
  });
</script>
farhantechno
  • 595
  • 6
  • 15

0 Answers0