...

View Full Version : Still submitting



CoolAsCarlito
03-09-2011, 10:27 PM
For some reason it still submits the form even if there is messages for no input.



<?php

session_start(); // Access the existing session

// Include the database page
require ('../../inc/dbconfig.php');

$userID = $_SESSION['userID'];

?>

<script type="text/javascript">
$(document).ready(function() {
$('div.message-error').hide();
$('div.message-success').hide();
$("#arenaForm").validate({
rules: {
arenaName: "required",
locationName: "required",
capacity: "required",
},
messages: {
arenaName: "Please enter the arena name",
locationName: "Please enter a city and state",
capacity: "Please enter the arena's capacity"
}
});
$("input.submit").click(function() {
var userID = $("input#userID").val();
var arenaName = $("input#arenaName").val();
var locationName = $("input#locationName").val();
var capacity = $("input#capacity").val();
var dataString = 'userID=' + userID + '&arenaName=' + arenaName + '&locationName=' + locationName + '&capacity=' + capacity + '&submitArena=True';
$.ajax({
type: "POST",
url: "processes/arena.php",
data: dataString,
success: function(myNewVar) {
if (myNewVar == 'good') {
$('div.message-error').hide();
$("div.message-success").html("<h6>Operation successful</h6><p>" + arenaName + " was saved successfully.</p>");
$("div.message-success").show().delay(10000).hide("slow");
$(':input','#arenaForm')
.not(':submit, :hidden')
.val('')
} else {
$('div.message-success').hide();
$("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + arenaName + " already exists in the database.</p>");
$("div.message-error").show();
}
}
});
return false;
});
});
</script>

<!-- Form -->
<form action="#" id="arenaForm" >
<fieldset>
<legend>Add New Arena</legend>
<div class="field required">
<label for="arenaName">Arena Name</label>
<input type="text" class="text" name="arenaName" id="arenaName" title="Arena Name"/>
<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
</div>
<div class="field required">
<label for="locationName">Location</label>
<input type="text" class="text" name="locationName" id="locationName" title="Location Name"/>
<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
</div>
<div class="field required">
<label for="capacity">Capacity</label>
<input type="text" class="text" name="capacity" id="capacity" title="Capacity"/>
<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
</div>
<input type="hidden" name="userID" id="userID" value="<?php echo $userID; ?>" />
<input type="submit" class="submit" name="submitArena" id="submitArena" title="Submit Arena" value="Submit Arena"/>
</fieldset>
</form>
<!-- /Form -->
<!-- Messages -->
<div class="message message-error">
<h6>Required field missing</h6>
<p>Please fill in all required fields. </p>
</div>
<div class="message message-success">
<h6>Operation succesful</h6>
<p>Arena was added to the database.</p>
</div>
<!-- /Messages -->

devnull69
03-10-2011, 06:53 AM
Exactly what part of the code is supposed to prevent submitting?

I think the line "return false" would do the trick ... but you put it inside the .click() handler of the submit button. If you put it into the submit() handler of the associated form, it will work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum