Jump to content

AJAX Form Submit


CONFUSIONUK

Recommended Posts

I'm just wondering if someone could give me a hand with some validation on a form I have set up for a shoutbox.

Below is the script I have made up to check on the click of "#shout_submit" and post the data through another script on the site, what I'm after is if someone could give me an example or some pointers as to how I can maybe use the else if statements as in php to firstly check the form has been filled out, if not display a warning using the alert feature in java prompting to input the name and message or if successful just carry on and process the code below.

 

I have tried a few things but they didn't work and also kept refreshing the page on submit, any help would be highly appreciated!  :-*

 

$(function() {
    $("#shout_submit").click(function() {		
        $.ajax({
            type: "POST",
            url: "get.php?shout",
            data: $("#shoutbox_form").serialize(),
            success: function(){
            $('#shouts').load('get.php?shouts=5');
            $('#shoutbox_form')[0].reset();
        }
    });
    return false;
});
});

Link to comment
Share on other sites

I hope this is what your looking for. its a small script that checks if the submit button with the name of submit is pressed, and if a certain value or condition is met. I dont know anything about ajax yet, but for php this works.

 

<?php
$x = 1; // assign a value to variable x

if (isset($_POST['submit'])){
    if ($x==$_POST['your_post_value_here']){  
        echo 'you pressed submit '; // or code or form to be executed
    }else{ //if submit wasn't pressed
         echo 'you didn\'t press submit';
  }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.