PDA

Click to See Complete Forum and Search --> : Editing this script...


iamme2007
Apr 25th, 2007, 06:13 PM
Download the attachment, does anyone know how I would beable to make a form on a webpage so people can enter their name and it'll goto a new page showing the image with the name they entered? The only way you can do it right now is by entering the name after ?=

penagate
Apr 25th, 2007, 07:02 PM
I can't download the attachment right now, but have a read of HTML Forms and Input (http://www.w3schools.com/html/html_forms.asp).

iamme2007
Apr 25th, 2007, 08:34 PM
This is what I've done so far:-


<form name="input" action="localhost/sig/stats.php/stats/$name" method="get">

Name:
<input type="text" name="name" value="" size="20">

<input type="submit" value="Submit">


</form>

But when I click submit it doesn't get the name so the signature has no name on it, is there anything wrong in that code?

kows
Apr 25th, 2007, 09:18 PM
yes. that's wrong.

I haven't downloaded the attachment (and I can't right now -- so really if you could post anything relevant that would be great!), but.. do you just basically want to build the image using the form rather than editing the URL manually?

first off, don't forget the HTTP part of your URL.

secondly, you should understand how GET works. if you submit a form via GET, then ALL elements in the form that are NAMED objects will be reproduced in the query string. this means that if you were submitting to image.php, and you have a form with an input named "name", then the form would essentially submit to.. image.php?name=[value_you_put_in_the_field]. understand? so.. with what you were currently doing in the example you posted, you would essentially be creating: "localhost/sig/stats.php/stats/$name?name=[value]" (and since you didn't echo out '$name', it would literally show the scalar character). so, if your script works by going to 'http://localhost/sig/stats.php?name=[value]' (to display [value] in the image), then you can easily make a form that just submits to that URL.
<form name="input" action="http://localhost/sig/stats.php" method="get">
<input type="text" name="name" size="20 />
<input type="submit" value="go" />
</form>
then, you'll be submitting to 'http://localhost/sig/stats.php?name=[value]'. however, because of the way you formatted your URL (/sig/stats.php/stats/[value], rather than using a query string), you might need to get a little involved. in this case, you could POST your form and then just redirect with a header to the correct URL. something like this:
<?php
//submitting?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//make sure our variable is not empty and does exist
if(isset($_POST['name']) && $_POST['name'] != ""){
//redirect
header("Location: http://localhost/sig/stats.php/stats/" . urlencode($_POST['name']));
exit;
}else{
//something was empty, show the form again
$error = true;
}
}

if(isset($error) || $_SERVER['REQUEST_METHOD'] != "POST"){
//show the form
?>
<form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="name" size="20" />
<input type="submit" value="go" />
</form>
<?php } ?>
so.. basically, when you submit that script it will submit to itself but redirect the user to the URL formatted like: http://localhost/sig/stats.php/stats/[value]

hope that made sense! I'm in sort of a rush. all untested code, but it should be fine. post any questions you might have!

iamme2007
Apr 25th, 2007, 09:56 PM
Thanks, I got it to work but one last thing, is it possible to make it not redirect show when the button is pressed the image shows up and a textbox that'll give the URL to it? And heres the code (had to edit yours abit)


<?php
//submitting?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//make sure our variable is not empty and does exist
if(isset($_POST['name']) && $_POST['name'] != ""){
//redirect
header("Location: http://localhost:2000/sig/stats.php/stats/". urlencode($_POST['name']. ".gif"));
exit;
}else{
//something was empty, show the form again
$error = true;
}
}

if(isset($error) || $_SERVER['REQUEST_METHOD'] != "POST"){
//show the form
?>
<form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="name" size="20" />
<input type="submit" value="go" />
</form>
<?php } ?>

Heres a example:-

http://www.draynor.net/forum/stat-signatures.html

kows
Apr 25th, 2007, 11:47 PM
that's easy.

<?php
//submitting?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//make sure our variable is not empty and does exist
if(isset($_POST['name']) && $_POST['name'] != ""){
//display image
$img = "http://localhost:2000/sig/stats.php/stats/{$_POST['name']}.gif";
?>
<img src="<?php echo $img; ?>" /><br /><br />
<input type="text" value="<?php echo htmlentities($img); ?>" size="20" />
<?php
}else{
//something was empty, show the form again
$error = true;
}
}

if(isset($error) || $_SERVER['REQUEST_METHOD'] != "POST"){
//show the form
?>
<form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="name" size="20" />
<input type="submit" value="go" />
</form>
<?php } ?>