Link to home
Start Free TrialLog in
Avatar of madscientist
madscientist

asked on

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

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.
Avatar of Mark Gilbert
Mark Gilbert
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of GarbsTheTurtle
GarbsTheTurtle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial