PDA

View Full Version : Passing variables from a form...



agent007
January 10th, 2002, 19:07
Okay, I'm trying to make a feedback script where visitors can submit feedback to me using a form. I'm trying to use the forms to pass several variables ($name, $email, etc. etc.) to another script (submit.php) but it's not working. Here's my form code:


<form action="submit.php?name=<?=$name;?>&email=<?=$email;?>" method="POST">
<table border="0" cellspacing='0' cellpadding='0'>
<tr>
<td>
<b>Name/Alias:</b>
</td>
<td>
<input type="text" name="name" value="">
</td>
</tr>
<tr>
<td>
<b>Email:</b>
</td>
...
other form stuff goes here...
...
</td>
</tr>
<tr>
<td>
<input type=submit value="Submit" name="sfeedback">
</td>
</tr>
</table>
</form>


And here's the code for my submit.php script:



<?
if (empty($name) or ($name == "name")) {
echo "Make sure you fill out your name!";
}

if (empty($email) or ($email == "email")) {
echo "Make sure you fill out your email!";
}

else {
$sendto = "agent@mapcentral.ne.gs";
$content = "content will go here once I figure out how to pass the variables.";
$subject = "[MAPCENTRAL] Submission";
$header = "From: $email";
mail($sendto, $subject, $content, $header);
echo "Thanks, <b><a href=\"mailto:<?=$email;?>\"><?=$name;?></a></b>, your feedback has been sent. Here's what you entered:<BR>
<table cellspacing='0' cellpadding='0' border='0'>
<tr>
<td>
<b>Name/Alias:</b>
</td>
<td>
<?=$name;?>
</td>
</tr>
<tr>
<td>
<b>Email:</b>
</td>
<td>
<?=$email;?>
</td>
...
other form stuff goes here...
...
</tr>
</table>
";
}
?>


Any ideas? I'm not getting any parse errors or any other kind of error. It's just not passing the variables. When I click submit, the address bar doesn't show that it has added the variables in. Ex, it shows: submit.php?name=&email= instead of submit.php?name=myname&email=myemail@something.com. Any ideas?

EDIT: Of course, the "other form stuff..." thing has some other text boxes, but it shouldn't make any difference.

vorapoap
January 10th, 2002, 19:13
From a quick look

You should use
<FORM ACTION="submit.php" METHOD="POST">

The browser will do the work for do..

This is sure to be incorrect.
<form action="submit.php?name=<?=$name;?>&email=<?=$email;?>" method="POST">

agent007
January 10th, 2002, 19:15
Wow, fast reply :)

But I've already tried that before I put in the <?=$variable;?> tags... Still doesn't show anything! I've also tried changing the form a bit for a staff application form and changed the variables a bit but it still doesn't work. :(

Take a look at http://mapcentral.oe-network.com/contact.php at the bottom.

vorapoap
January 10th, 2002, 19:22
I think you need to use

<? print $name ?>

or

<? echo $name ?>

to display it
never heard before that this "<?=$name;?>" would work

agent007
January 10th, 2002, 19:46
I'm pretty sure it does... For example, if you put this is a script:



<?
$something = "some text here";
?>
blah blah blah blah <?=$something;?>


It should work.

agent007
January 10th, 2002, 19:49
I just tried doing what you said anyways (echo instead of =) but it still doesn't work :mad:

spec
January 10th, 2002, 19:58
try making th variables Global
ie
else{
global $name, $email, $face,$anotherface;

Blah blah blah

agent007
January 10th, 2002, 20:02
Originally posted by spec
try making th variables Global
ie
else{
global $name, $email, $face,$anotherface;

Blah blah blah

Sorry, I'm a complete PHP newbie :o

Could you post an example of how/where to put it in the script? Thanks! :D

vorapoap
January 10th, 2002, 20:32
Your server's configuration might be quite unusual... it should work by now.. However PHP can detect that those variables exist but why no value??.. this is so strange.. I think you 'd better ask your admin.

spec
January 11th, 2002, 00:12
else {

Global $var

$sendto = "agent@mapcentral.ne.gs";
$content = "content will go here once I figure out how to pass the variables.";
$subject = "[MAPCENTRAL] Submission";
$header = "From: $email";
mail($sendto, $subject, $content, $header);
echo "Thanks, <b><a href=\"mailto:<?=$email;?>\"><?=$name;?></a></b>, your feedback has been sent. Here's what you entered:<BR>
<table cellspacing='0' cellpadding='0' border='0'>
<tr>
<td>
<b>Name/Alias:</b>
</td>
<td>
<?=$name;?>
</td>
</tr>
<tr>
<td>
<b>Email:</b>
</td>
<td>
<?=$email;?>
</td>
...
other form stuff goes here...
...
</tr>
</table>
";
}
?>

agent007
January 11th, 2002, 07:32
Originally posted by spec
else {

Global $var

$sendto = "agent@mapcentral.ne.gs";
$content = "content will go here once I figure out how to pass the variables.";
$subject = "[MAPCENTRAL] Submission";
$header = "From: $email";
mail($sendto, $subject, $content, $header);
echo "Thanks, <b><a href=\"mailto:<?=$email;?>\"><?=$name;?></a></b>, your feedback has been sent. Here's what you entered:<BR>
<table cellspacing='0' cellpadding='0' border='0'>
<tr>
<td>
<b>Name/Alias:</b>
</td>
<td>
<?=$name;?>
</td>
</tr>
<tr>
<td>
<b>Email:</b>
</td>
<td>
<?=$email;?>
</td>
...
other form stuff goes here...
...
</tr>
</table>
";
}
?>

I'll give it a try, thanks.