PHP help please!

Status
Not open for further replies.

darkdrift

New member
Jun 24, 2006
694
5
0
I am in need of someone who can help me pass a variable to the end of a URL, when a form is submitted. I am a complete newb at PHP, and need to get this done ASAP. for example, when a user submits information in a form, I need it to redirect them to www.url.com/something/{what they put in the form here!}

Thanks!

pm me your AIM if you can help or just post the code here.
 


if you're passing through method="post" then you need to use $variable=$_POST['variable'];
if you're passiing through method="get" then you need $variable=$_GET['variable'];
 
You could do this.

Setup:
1. Set your form to [method="post"] (get would work as well)
2. Set your form to [action=""] (to reload this same page)
3. Create an input text box with, for example, [name="userInput"]
4. Create a submit button with, for example, [name="submit"]

PHP:
At the top of your page, check if the form was submitted. If it was, then redirect the user.
Code:
if (isset($_POST['submit'])) {
     header('Location: http://www.url.com/something/'.$_POST['userInput']);
}
You would need to make sure these directories/pages exist by either restricting the input (with a select box instead of a text box) or by using mod_rewrite (or something similar).
 
One more variant:

<FORM NAME="f1" onSubmit="location.href='http://www.url.com/something/'+f1.smth.value; return false;">
smth: <input name=smth>
<input type=submit>
</FORM>
 
Status
Not open for further replies.