I was just wandering, if I had a text box in a form, how could I get the text that a user submitted in that text box into a variable?
Thanks
Rob
_
Jul 13 2005, 05:41 PM
If the form's 'method' is POST, you can get it as $_POST['name of field'], if it's GET, it's just $_GET['field name'].
Rob_BCFC
Jul 13 2005, 05:54 PM
Ok thanks. I am a bit of a n00b to PHP so thank you.
Rob_BCFC
Jul 13 2005, 06:21 PM
I am having a few problems with this. What I would like to do is have a form on one page, where a user inputs the site they would like to go to. Then, on my second page (which processes the form), I would like to have an include statement with that site in, if you get me. Don't ask why it's not worth going into. Thanks a lot.
<? $includethis = $_POST['includethis']; include $includethis; ?>
or include $_POST['includethis']; o.O
Phil Mossop
Jul 13 2005, 06:57 PM
Just a tad insecure though...
Should really have a set of pages that can be included.
process.php
CODE
<?php
$valid = array( 'mypage.html', 'otherfile.txt' );
if ( in_array($_POST['includethis'], $valid) ) { include "./".$POST['includethis']; } else { header("Location: ./form.html"); }
?>
Starnox
Jul 13 2005, 06:59 PM
QUOTE(Phil Mossop @ Jul 13 2005, 07:57 PM)
Just a tad inscure thoigh....
Well its what he wanted
Kenny Pollock
Jul 13 2005, 07:06 PM
QUOTE(Starnox @ Jul 13 2005, 02:55 PM)
or include $_POST['includethis']; o.O
Complain, complain, complain!
Rob_BCFC
Jul 13 2005, 07:32 PM
Thanks so much guys I really needed this. Just one more thing though. It wont load relative images, etc. How can I fix this? Thank you so much for your help!
Also it wont redirect pages, also because of the relative problem.
For example:
If I typed in www.bbc.co.uk in the file /test/form.html it loads up the text but it looks for the images on my server (/test/1.jpg, etc). is there anyway i could replace the /test/ with the users input (in this case www.bbc.co.uk)?
_
Jul 13 2005, 08:24 PM
You want to redirect?
CODE
header("Location: {$_POST['fieldname']}");
Rob_BCFC
Jul 13 2005, 08:27 PM
No I mean when a user types in a website in form.html, that website might redirect somewhere else using a relative URL, meaning it wont work.