In forms, I have the button type submit
which when clicked will be intercepted by jQuery in order to make validations to the content of the form before sending it to the PHP process via Ajax.
Form
<?php
$html = '
<form action="'.CONF_FORM_ACTION_REGISTRATION.'" method="post" autocomplete="off" class="jForm">
<p>
<span class="icon-user"></span>
<label for="formRegistration-usr">
'.LANG_WORD_NAME.'
<span class="msg"></span>
</label>
<input id="formRegistration-usr" class="roundCorners jValidate" name="formRegistration-usr" required="required" type="text" placeholder="'.LANG_PLACEHOLDER_NAME.'" data-validation="notEmpty">
</p>
<p>
<span class="icon-envelope"></span>
<label for="formRegistration-email">
'.LANG_SENTENCE_YOUR_EMAIL_ADDRESS.'
<span class="msg"></span>
</label>
<input id="formRegistration-email" class="roundCorners jValidate" name="formRegistration-email" required="required" type="text" placeholder="'.LANG_PLACEHOLDER_EMAIL.'" data-validation="email">
</p>
<p>
<span class="icon-key"></span>
<label for="formRegistration-pwd">
'.LANG_SENTENCE_YOUR_PASSWORD.'
<span class="msg"></span>
</label>
<input id="formRegistration-pwd" class="roundCorners" name="formRegistration-pwd" required="required" type="password" placeholder="'.LANG_PLACEHOLDER_PASSWORD.'">
</p>
<p>
<span class="icon-key"></span>
<label for="formRegistration-chkPwd">
'.LANG_SENTENCE_CONFIRM_YOUR_PASSWORD.'
<span class="msg"></span>
</label>
<input id="formRegistration-chkPwd" class="roundCorners jValidate" name="formRegistration-chkPwd" required="required" type="password" placeholder="'.LANG_PLACEHOLDER_PASSWORD.'" data-validation="chkPwd">
</p>
<p class="button">
<span class="formMsg"></span>
<input name="formRegistration-smt" id="formRegistration-smt" class="btn_blue roundCorners" type="submit" value="'.LANG_WORD_REGISTER.'">
</p>
</form>';
?>
jQuery code
/**
* PROCESS FORMS
* Actions associated with the submit of several similar forms.
*/
function processForms() {
$(".jForm").on("submit", function(e) {
e.preventDefault();
var $this = $(this),
$formMsg = $this.find(".formMsg");
if (mandatoryFieldsFilled($this)) {
$.ajax({
type : "POST",
url : "/components/inc/ajax/users.ajax.php",
async : false,
data : $this.serialize(),
dataType: "json",
success : function(data) {
var arr = data;
if (arr[0]=="success") {
$formMsg.removeClass("error").addClass("success");
} else {
$formMsg.removeClass("success").addClass("error");
}
$formMsg.html(arr[1]);
autoHideModalForm($this, 4000);
}
});
} else {
$formMsg.removeClass("success").addClass("error").html(LANG_USR_MSG_MANDATORY_FIELD_EMPTY);
}
});
}
The problem is that all fields of the form are sent in POST
of Ajax with the exception of the submit
button, being what I use to discern through the name of the form, which form to process on the PHP side .
Question
How can I include the submit
button in the POST array generated by serialize
?