Jump to content

My Code Isn't Working?


happyhippy

Recommended Posts

Code goes no place but changes some figures on the tool bar.  :wtf:

 

<?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>

Link to comment
https://forums.phpfreaks.com/topic/246845-my-code-isnt-working/
Share on other sites

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'] ?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.