Need to stop post/PHP from executing...

Discussion in 'Scripts' started by TechNoir, Feb 21, 2013.

to remove all ads.
  1. TechNoir

    TechNoir New Member

    Messages:
    6
    Hi there!

    I'm working on a form for our company website, and despite having reCaptcha successfully installed on it, my boss insisted he wanted one of those "2+2=4" boxes. So I resorted to a simple Javascript. The problem is, I have formmail set up... so when the wrong number is entered, an alert comes up telling the user such, but then it goes through with the POST action and sends the email anyway. I can catch it when the user leaves the field blank, due to the required field tag, but... is it possible to stop the page in the above instance?

    code (edited):

    If someone could help, I'd really appreciate it.
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,657
    Use a button type input and submit the form with javascript.
     
  3. TechNoir

    TechNoir New Member

    Messages:
    6
    Sorry... I don't know how to do that. I'm in over my head with scripting.
     
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,657
  5. TechNoir

    TechNoir New Member

    Messages:
    6
    Ahhh... where do I put that code into the "all good" part? Do I replace it? List it after what's there? Do I need to remove POST? I tried several different ways but the form won't submit.

    Thanks again for your help!
     
  6. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,657
    type="button" onclick="addNums(); formSubmit()" />


    This will run the script AND submit without waiting for the script to ok the answer, the javascript has to send the submit ONLY when the match is made correctly.
     
  7. TechNoir

    TechNoir New Member

    Messages:
    6
    Hi... I'm sure this seems really simple to you, but it makes no sense to me. I don't know Javascript. The submit button is now a "button" type and I took formSubmit() out, but now the form will not submit at all even when the answer's correct. I assume I'm supposed to place this code somewhere that you linked me to? (http://www.w3schools.com/jsref/met_form_submit.asp) ...But I don't know where. I don't know how to make this work or I wouldn't be desperately seeking help on a forum.

    Thanks...
     
  8. Dennis Carnegie Jr

    Dennis Carnegie Jr New Member

    Messages:
    10
    Hi, Are you still in need of assistance in getting this working? I see Chris was helping you, but sounds like you are not understanding what needs to be done. You actually need to keep the formsubmit() in there so this way when you do the onclick, it will first validate the answer, and then after validating then it will submit the form. If you need further assistance, let us know.
     
  9. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,657
    Ermm? That was FIVE YEARS AGO, it's probably safe to assume that it is either fixed or of no importance at all any longer.
     

Share This Page