...

View Full Version : Why wont this bloody form work???



BerlinIT
09-10-2003, 04:33 PM
It should be straight forward - i have other files almost identical that work fine... have i missed something?

(i've removed javascript form validators as its not necessary to show them here to solve the problem. it doesnt work without them eitheir)

Any suggestions would be massively appreciated. i suspect its something so small i cant see it, but its driving me bananas.

thanks



File1:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<p>Contact us to find out about upcoming events, to join our mailing list, to
contribute photos or other material, or for anything else that tickles your
fancy...</p>

<table>
<!-- Table 4 -->
<FORM ACTION="contactus_2.php" METHOD="post">
<TR>
<TD WIDTH='100%' class="contactheader">Name<BR>
<INPUT TYPE="text" NAME="name" SIZE="30" class="inputbox" VALUE="">
</TD>
</TR>
<TR>
<TD WIDTH='100%' class="contactheader">Email<BR>
<INPUT NAME='email' TYPE='text' class="inputbox" onBlur="MM_validateForm('from','','NisEmail');return document.MM_returnValue" VALUE='' SIZE='30'>
</TD>
</TR>
<TR>
<TD WIDTH='100%' class="contactheader">Message</TD>
</TR>
<TR>
<TD valign='top'>
<TEXTAREA COLS='45' ROWS='8' NAME='message' class="inputbox" wrap="VIRTUAL"></TEXTAREA>
</TD>
</TR>
<tr>
<TD valign='top' class="contactheader">Would you like to join our mailing list, to be notified of upcoming events?</TD>
</tr>
<TR>
<TD align="left" class="contactheader">
Yes <input name="maillist" type="radio" value="Yes" checked> No <input name="maillist" type="radio" value="No">
</TD>
</TR>
<TR>
<TD HEIGHT='20' VALIGN='bottom' align="left">
<br>
<INPUT NAME="send" VALUE="Send" TYPE="submit" class="button" onClick="validate()">
</TD>
</TR>

</form>
</TABLE>
</body>
</html>


FILE2 (contactus_2.php):

<?

Function GetMsgInfo()
{
$Name = $HTTP_POST_VARS["name"] ;
$Email = $HTTP_POST_VARS["email"] ;
$Message = $HTTP_POST_VARS["message"] ;
$MailList = $HTTP_POST_VARS["maillist"] ;
}

Function MailMsgInfo()
{
global $Name ;
global $Email;
global $Message;
global $MailList ;

$Text= "Name: " .$Name ."\n" ."E-Mail: " .$Email ."\n \n" ."Message: " .stripslashes($text) ."\n \n" ."Mail List: " .$maillist ;
$From= $Name . "<" . $Email . ">";
mail("webmessage@berlinit.com", "Sutter Cain Webmail Message", $Text, "From:" .$From );
}

Function DisplayMsgInfo()
{
global $Name ;
global $Email;
global $Message;
global $MailList ;

?>
<table>
<tr>
<td colspan="2" align="left">
<p><strong>The following details have been emailed to the Sutter Cain Crew:</strong></p>
<p><strong>Name: </strong><? echo $Name ; ?> <br>
<strong>Email: </strong><? print $Email ; ?> <br><br>
<strong>Message: </strong><? print $Message ; ?> <br><br>
<strong>Mailing List Subscription: </strong><? print $MailList ; ?> <br><br>
</p>

<p><strong>Thank you for getting in touch. We appreciate your feedback.</strong> <br><br></p>
<p align="center"><a href="nextevent.html">[ Home ]</a></p>
</td>
</tr>
</table>
<? } ?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact Us 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

<? GetMsgInfo() ;
//MailMsgInfo() ;
DisplayMsgInfo() ;?>


</body>
</html>

mordred
09-10-2003, 04:59 PM
Originally posted by BerlinIT
It should be straight forward - i have other files almost identical that work fine... have i missed something?


Yes, you did. The description of the error or problem, and the expected behaviour of your code and what it did instead. Does it throw any errors? Does the mail not get send? Do some variables not have the right value? Does the server burst into flames?

Spookster
09-10-2003, 05:07 PM
And also why is your form bloody? Did you cut your finger and bleed on it?

missing-score
09-10-2003, 05:35 PM
lol @ spookster.


$Name ;
$Email;
$Message;
$MailList ;


correct me if i am wrong, but i dont see anywhere these vars are being used outside of functions... They are defined in a function, and are neither returned or made global...

so when you do this:

global $Name ;
global $Email;
global $Message;
global $MailList ;

it is not finding anything... If you define these variables outside of functions, you should be ok.

BerlinIT
09-11-2003, 01:53 AM
Originally posted by mordred
Yes, you did. The description of the error or problem, and the expected behaviour of your code and what it did instead. Does it throw any errors? Does the mail not get send? Do some variables not have the right value? Does the server burst into flames?

Oops, sorry.. i'm a goose.

Basically, the form is not passing the information to the variables in the contactus_2.php file. So whe i go to display the results, no form data is shown.

BerlinIT
09-11-2003, 02:00 AM
Originally posted by missing-score
correct me if i am wrong, but i dont see anywhere these vars are being used outside of functions... They are defined in a function, and are neither returned or made global...

so when you do this:

global $Name ;
global $Email;
global $Message;
global $MailList ;

it is not finding anything... If you define these variables outside of functions, you should be ok.

No, you're absolutely right. Putting everything outside of the functions actually works (! Why ddint i think of trying this??).. thanks for that missing-score. :)

So how come, if i put the table display inside the same function that gets the form data and writes them to variables, and then call that function from the body part at the bottom, ti doesnt work?? Theoretically its just 1 function being called so no globals required (is this assumption correct?). ie:

<?

Function GetMsgInfo()
{
$Name = $HTTP_POST_VARS["name"] ;
$Email = $HTTP_POST_VARS["email"] ;
$Message = $HTTP_POST_VARS["message"] ;
$MailList = $HTTP_POST_VARS["maillist"] ;
?>

<table>
<tr>
<td colspan="2" align="left">
<p><strong>The following details have been emailed to the Sutter Cain Crew:</strong></p>
<p><strong>Name: </strong><? echo $Name ; ?> <br>
<strong>Email: </strong><? print $Email ; ?> <br><br>
<strong>Message: </strong><? print $Message ; ?> <br><br>
<strong>Mailing List Subscription: </strong><? print $MailList ; ?> <br><br>
</p>

<p><strong>Thank you for getting in touch. We appreciate your feedback.</strong> <br><br></p>
<p align="center"><a href="nextevent.html">[ Home ]</a></p>
</td>
</tr>
</table>

<? } ?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact Us 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

<? GetMsgInfo() ; ?>

</body>
</html>

mordred
09-11-2003, 02:19 AM
In your function GetMsgInfo(), you use the variable $HTTP_POST_VARS, but it's nowhere defined in that function, so you need to explicitly import that variable by using

Function GetMsgInfo()
{
global $HTTP_POST_VARS;
$Name = $HTTP_POST_VARS["name"] ;
[...]

To confuse matters, exactly for this little nuissance the superglobal $_POST has been introduced in PHP 4.1. With that in mind you could've omitted importing the post variables array into the function's scope.

Function GetMsgInfo()
{
$Name = $_POST["name"] ;
[...]

Note that only the prefined arrays like $_GET, $_POST etc. exhibit this particular behaviour - other variables still need to be imported from the global scope.

BTW, I'd say it's common convention to write the function keyword in lowercase, but that's just a cosmetic nitpick. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum