在同一页面上处理多个表单PHP JQuery

时间:2015-05-10 11:46:50

标签: javascript php jquery html ajax

行!我在页面上有各种隐藏的表单,并且在表格提交Shipping Address上存储在会话中。

表格如下:

.chkhiddenform input {display:none}


表格1


<form role="form" class="form-horizontal chkhiddenform" method="post">
  <input type="text" class="form-control" id="bc_ship_zipcode" 
   name="bc_ship_zipcode" value="123456"/>
  <input type="text" class="form-control" id="bc_ship_name" 
   name="bc_ship_name" value="Test"/>
 <input type="text" class="form-control" id="bc_address" 
   name="bc_address" value="Test Address 1 Address 2"/>
 <button type="submit" class="select_btn btn btn-white"><span>Deliver 
 Here</span></button>   
</form>


表格2


<form role="form" class="form-horizontal chkhiddenform" method="post">
  <input type="text" class="form-control" id="bc_ship_zipcode" 
   name="bc_ship_zipcode" value="123456"/>
  <input type="text" class="form-control" id="bc_ship_name" 
   name="bc_ship_name" value="Test 2"/>
 <input type="text" class="form-control" id="bc_address" 
   name="bc_address" value="Test Address 1 Address 2 Address 3"/>
 <button type="submit" class="select_btn btn btn-white"><span>Deliver 
 Here</span></button>   
</form>

用于提交隐藏表单的JQuery如下:

$(".chkhiddenform").validate({
 var bc_name = $("#bc_ship_name").val();var bc_ship_zipcode = 
 $("#bc_ship_zipcode").val();var bc_address = 
 $("#bc_address").val();
 var dataString = 'bc_ship_name=' + bc_name + '&bc_ship_zipcode=' + 
                   bc_ship_zipcode + '&bc_address=' + 
                   bc_address
submitHandler: function() {
     $.ajax({
        url: 'process.php',
        type: 'POST',
        data: dataString,
        success: function(response) {
           if(response=='success'){
              window.location.replace('next-screen');
           }
        }
     });
}
});

Process.php如下:

$sql1 = "select * from `additional_address` WHERE `email` = ? ";
$result1 = 
DB::instance()->prepare($sql1)->execute(array($_SESSION['array']
['email']))->fetchAll();
$_SESSION['address'] = reset ($result1);

但始终在提交时,表单1的值将进入下一页。请告诉我问题在哪里?

0 个答案:

没有答案