happyhippy Posted September 10, 2011 Share Posted September 10, 2011 Code goes no place but changes some figures on the tool bar. <?php ini_set('display_errors', 1); error_reporting(E_ALL); function OnSubmitForm() { $choose = ""; $variable1 = ""; $variable2 = ""; $choose = $_GET["pages"]; $variable1 = $_GET["page1"]; $variable2 = $_GET["page2"]; if ($choose == $variable1) { header("Location: http://url.com/page1"); } if ($choose == $variable2) { header("Location: http://url.com/page2"); } } ?> <form name="pages" onsubmit="return OnSubmitForm()"> <input type="text" name="call" size="25"> e<select name="pages"> <option name="page1" value="non1">page1</option> <option name="page2" value="non2">page2</option> </select> <input type="submit" name="submit" value="submit"> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/ Share on other sites More sharing options...
redarrow Posted September 10, 2011 Share Posted September 10, 2011 this tell me your getting what from what in the url HELP? $variable1 = $_GET["page1"]; $variable2 = $_GET["page2"]; Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/#findComment-1267681 Share on other sites More sharing options...
Sanjib Sinha Posted September 10, 2011 Share Posted September 10, 2011 So far I know, form onSubmit is a scripting event that occurs when the user attempts to submit the form to the CGI. Form onSubmit can be used to do some error checking on the form data, and to cancel the submit if an error is found. Have you tried keeping form action blank like this: <form action="" or $_SERVER['PHP_SELF'] ? Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/#findComment-1267684 Share on other sites More sharing options...
mikesta707 Posted September 10, 2011 Share Posted September 10, 2011 You can't use the onsubmit event with PHP. This functionality is reserved for javascript. If you want a function to run on the submit event, you will need to convert your php code to javascript and call it that way Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/#findComment-1267752 Share on other sites More sharing options...
happyhippy Posted September 10, 2011 Author Share Posted September 10, 2011 how would I do this in action? Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/#findComment-1267776 Share on other sites More sharing options...
mikesta707 Posted September 10, 2011 Share Posted September 10, 2011 You can't call a PHP function with anything but PHP. You have to remember that PHP is executed by the server when the page is requested. by the time the HTML is output and stuff (whatever the user sees) is all clientside. If you want you could use AJAX, but it would probably be easier to just use javascript. Or you could just make it a 2 step process, and have the form submit to a page that would execute that PHP, and that page redirects based on whatever criteria you have. Quote Link to comment https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/#findComment-1267782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.