Cannot use PHP's if(isset()) if form submitted with Javascript

madscientist used Ask the Experts™
Hello all,

I have an HTML form which I'm processing with PHP, and I'm checking if the form has been submitted using if(isset($_POST['submit'])), and if the form has not been submitted i throw up an error message and kill the script. My problem is that as well as using my normal submit button (<input type="submit" name="submit" id="submit" value="Submit Form" />) I would like to use a link with javascript to submit the form. I have my javascript as document.getElementById('form_name').submit(); but if I use the javascript to submit the form, PHP responds with the error message. If I remove my if(isset($_POST['submit'])) conditional, everything is fine, but ideally I would like this in place.

How do I solve this?

Many Thanks, Adam.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mark GilbertSenior Performance Engineer

If you use this javascript link:

javascript: document.form1.submit();

The form should submit correctly.  Make sure to replace form1 with the name of your form.

Hope this helps.
use if(isset($_POST['someOtherField'])) to check if the form has been submitted. $_POST['submit'] won't have a value if the Submit button isn't clicked directly. If you have a hidden field, or a select box (something that will definitely have a value regardless of user input/manipulation), use that instead.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial