I have a form where it is validated by jqBootstrapValidation.js, and it is sent to another file, which is the file below:
// Contact Form Scripts
$(function() {
$("#usuariosForm input,#usuariosForm textarea").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {
// additional error messages or events
},
submitSuccess: function($form, event) {
event.preventDefault(); // prevent default submit behaviour
// get values from FORM
var txtnome = $("input#txtnome").val();
var ememail = $("input#ememail").val();
var txtusuario = $("input#txtusuario").val();
var pwdsenha = $("input#pwdsenha").val();
var urltxt = $("input#urltxt").val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
firstName = name.split(' ').slice(0, -1).join(' ');
}
$('#submit').html("...Enviando");
$('#submit').prop("disabled", true);
$.ajax({
url: urltxt,
type: "POST",
data: {
txtnome: txtnome,
ememail: ememail,
txtusuario: txtusuario,
pwdsenha: pwdsenha
},
cache: false,
success: function() {
// Success message
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-success')
.append("<strong>Registro realizado com sucesso</strong>");
$('#success > .alert-success')
.append('</div>');
//clear all fields
$('#usuariosForm').trigger("reset");
$('#submit').html("Enviar mensagem");
$('#submit').prop("disabled", false);
},
error: function() {
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-danger').append($("<strong>").text("Desculpe " + firstName + ", ocorreu um erro. Por favor tente novamente!"));
$('#success > .alert-danger').append('</div>');
//clear all fields
$('#usuariosForm').trigger("reset");
},
});
},
filter: function() {
return $(this).is(":visible");
},
});
$("a[data-toggle=\"tab\"]").click(function(e) {
e.preventDefault();
$(this).tab("show");
});
});
/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
$('#success').html('');
});
But I'm in trouble, as I have several forms I always wanted to use the same function. and pass the url to it to do the sql correctly, that is, if I go to the user registration page it will do user registration. if it passes update_user it goes to the user change page. I tried a method of passing the url to ajax as follows:
<input type="text" name="urltxt" id="urltxt" class="form-control text-center" value="?folder=usuarios/&file=ins_usuarios_usuarios&ext=php" data-validation-required-message="Por favor não mude os dados." required>
And in the file it would receive in a variable, but it is not working. How can I do this? thank you very much! NOTE: The nomenclature of my pages are:? Folder = users / & file = ins_user_users & ext = php
I debugged the code see: