Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Still submitting

    For some reason it still submits the form even if there is messages for no input.

    Code:
    <?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 -->

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,388
    Thanks
    11
    Thanked 565 Times in 558 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •