Help - Search - Members - Calendar
Full Version: PHP Question
Invision Power Services > Community Forums > Community Web Design and Coding
Rob_BCFC
Hi,

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
_
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']. original.gif
Rob_BCFC
Ok thanks. I am a bit of a n00b to PHP so thank you.
Rob_BCFC
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. original.gif
Kenny Pollock
form.html
CODE
<form action="process.php" method="post">
<input type="text" name="includethis" />
<input type="submit" value="Include This!" />
</form>

process.php
CODE
<?
$includethis = $_POST['includethis'];
include $includethis;
?>
Starnox
QUOTE(Kenny Pollock @ Jul 13 2005, 07:50 PM) *
form.html
CODE
<form action="process.php" method="post">
<input type="text" name="includethis" />
<input type="submit" value="Include This!" />
</form>

process.php
CODE
<?
$includethis = $_POST['includethis'];
include $includethis;
?>


or include $_POST['includethis']; o.O
Phil Mossop
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
QUOTE(Phil Mossop @ Jul 13 2005, 07:57 PM) *
Just a tad inscure thoigh....


Well its what he wanted tongue.gif
Kenny Pollock
QUOTE(Starnox @ Jul 13 2005, 02:55 PM) *
or include $_POST['includethis']; o.O

Complain, complain, complain! tongue.gif
Rob_BCFC
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)?
_
You want to redirect?

CODE
header("Location: {$_POST['fieldname']}");
Rob_BCFC
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.
Kenny Pollock
Try this for process.php
CODE
$site = file_get_contents($_POST['includethis']);
echo str_replace("src=\"", src=\"$_POST['includethis']/", $site);

Maybe... it won't work for all sites though, you're better off doing:
CODE
header("Location: {$_POST['includethis']}");
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.