SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    action form in javascript

    Hi, I have setup a basic enquiry form with a Captcha - once the code has been inserted and is correct I want to action the form (submit). I have been advised that javascript is a good method for this.


    PHP Code:
    <?php

    session_start
    ();
    if(
    $_SERVER['REQUEST_METHOD'] == 'POST'){
        
    $vResult '';
        if(
    strtolower($_SESSION['security_code']) != strtolower($_POST['security_code'])){
            
    $vResult 'Invalid code!';
        }
        else{
            
    "/enquiry.php"
        
    }
    }
    ?>
    I want to submit the form to /enquiry.php - I tried header(Location.. and realised that just redirects, and doesn't submit the form.

    Any suggestions or tips would be great.

    Note, the above script is loaded before the page so that code is above the <html><body>

    Cheers,

    Paul

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2 options you have are

    1) in enquiry.php, check the captcha value the user entered. If it is correct, continue executing enquiry.php or else redirect back to the form page.

    2) in the form page, have an onsubmit event handler that sends a synchronous ajax request to the server to check the captcha value. If the ajax response says the value is correct, the event handler should return true (which then allows the form to be submited) or else return false which will stop the form from being submitted.


Bookmarks

Posting Permissions

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