Forum Moderators: open

Message Too Old, No Replies

FORM posting to variable action pages

         

Jeremy_H

6:41 am on Dec 5, 2005 (gmt 0)

10+ Year Member



Hello,

I'm trying to create a form that will submit information to one of two different pages, based on which radio box was selected.

I know it's not complete, but here's what I have so far:

<form method="post" action="1.php">
<input name="name" type="text">
<input name="email" type="text">
<textarea name="text"></textarea>
<input name="site" type="radio" value="1.php">
<input name="site" type="radio" value="2.php">
<input type="submit" value="Submit">
</form>

Any advice?

I'm trying to make it when the radio button 1.php is selected, the form will post to 1.php, not 2.php.

Conversely, when 2.php is selected, the form will post to 2.php and not 1.php.

I'm also trying to look for an elegant solution that will work without fail, even if the user has JavaScript disabled. (If that's possible.)

Thanks for any help!

a1call

6:51 am on Dec 5, 2005 (gmt 0)

10+ Year Member



Hi Jeremy_H,
The only way I can think of to change the form's action from 1.php to 2.php is through javascript. But 1.php could have the php code to serve different pages depending on the value of the radio button selected.

Hester

10:19 am on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's the only way to ensure it doesn't fail if JavaScript is off. So add a variable to the php page like this:

<input name="site" type="radio" value="1.php">
<input name="site" type="radio" value="1.php?2">

If that works, you can test for the variable on the php page. If it's not present, do what 1.php does. If it's present, and equals 2, do what 2.php does.

Note: if you don't plan on using any other variables, you can avoid the syntax 1.php?variable=2 and just use 1.php?2 as PHP allows you to grab the contents of the posted variable via $_SERVER['QUERY_STRING'];

Jeremy_H

10:03 pm on Dec 8, 2005 (gmt 0)

10+ Year Member



Thanks both of you for your response.

I've been learning so much about PHP lately, and how wonderful it is!

It's lame that a variable like submitting pages can't be changed, but I found out how I can restructure the receiving page to show differently based upon the variable.

Thus I've combined both pages into one!

Thank you so much!