在创建名为jQuery.submit()
的隐藏字段之后,我无法使用submit
提交表单。但是,在我删除了隐藏字段之后,它可以正常工作,表单被提交。
代码如下:
<div>
<button type="button" id="btn-next" class="btn btn-primary" style="float:right; padding-left: 30px; padding-right: 30px">Next</button>
<button type="button" id="btn-prev" class="btn btn-primary" style="float:right; padding-left: 20px; padding-right: 20px; margin-right: 20px;">Previous</button>
<input type="hidden" name="sagar" value="submit" />
<!-- Add WordPress Nonce -->
<?php wp_nonce_field( 'add-product' ); ?>
</div>
JavaScript代码:
// Handle the 'next' button click.
jQuery('#btn-next').click(function(e){
e.preventDefault();
// Validate the product details.
var form = document.querySelector('form');
if (! validateForm(form, constraints[currentProductState]) ){
return;
}
if ( currentProductState == 2) {
jQuery("#form-add-product").submit();
return;
}
// If the form is ok, hide the current view.
jQuery(addProductState[currentProductState]).hide();
// Increment the state by 1.
if (currentProductState < 2) {
currentProductState++;
}
// Show the next view.
jQuery(addProductState[currentProductState]).show();
// Set the progress bar.
jQuery(progressBarList[currentProductState]).addClass("active");
});