Currently the table shows a different button for each mysql row, but only the first mysql row button works properly. When it works properly, the submit button saves the location row as a value for a javascript AJAX post. When it doesn't work properly the submit button refreshes the page.
This is the html and mysql form:
while($row = mysqli_fetch_array($result)) {
echo '<form class="form-signin" action="" method="POST" id="register-form"><tr>';
echo "<td><b>" . $row['product'] . "</b><br>";
echo "<td><b>" . $row['location'] . "</b><br>";
echo "" . $row['notes'] . "";
echo '
<input type="hidden" name="user_name" value="'. $row['product'].'" />
<input type="hidden" name="location" value="'. $row['location'].'" />
<input type="text" class="form-control" placeholder="Table Number" name="user_email" id="user_email" />
<input type="text" class="form-control" placeholder="Quantity" name="password" id="user_email" />
<button type="submit" class="btn btn-default" value="Submit form" name="btn-save" id="btn-submit">
<span class="glyphicon glyphicon-log-in"></span> '. $row['location'] .'
</button></td>';
echo "</tr></form>";
}
This is the javascript for "register-form" that posts:
{
var data = $("#register-form").serialize();
$.ajax({
type: 'POST',
url: 'register.php',
data: data,
beforeSend: function() {
$("#error").fadeOut();
$("#btn-submit").html('<span class="glyphicon glyphicon-transfer"></span> sending ...');
},
success: function(data) {}
})
}
Basically if the submit button is clicked need it to save for the respective row that is clicked, instead of taking a different action.
$('document').ready(function()
{
/* validation */
$("#register-form").validate({
rules:
{
},
messages:
{
user_name: "Enter a Valid Username",
password:{
required: "Provide a Password",
minlength: "Password Needs To Be Minimum of 8 Characters"
},
user_email: "Enter a Valid Email",
cpassword:{
required: "Retype Your Password",
equalTo: "Password Mismatch! Retype"
}
},
submitHandler: submitForm
});
/* validation */
/* form submit */
function submitForm()
{
var data = $("#register-form").serialize();
$.ajax({
type : 'POST',
url : 'register.php',
data : data,
beforeSend: function()
{
$("#error").fadeOut();
$("#btn-submit").html('<span class="glyphicon glyphicon-transfer"></span> sending ...');
},
success : function(data)
{
if(data==1){
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-danger"> <span class="glyphicon glyphicon-info-sign"></span> Sorry email already taken !</div>');
$("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> Create Account');
});
}
else if(data=="registered")
{
$("#btn-submit").html('Ordered');
// setTimeout('$(".form-signin").fadeOut(500, function(){ $(".signin-form").load(""); }); ',5000);
}
else{
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-danger"><span class="glyphicon glyphicon-info-sign"></span> '+data+' !</div>');
$("#btn-submit").html('<span class="glyphicon glyphicon-log-in"></span> Create Account');
});
}
}
});
return false;
}
/* form submit */
});