Page 1 of 1

Form Code Problem

Posted: Sun Feb 01, 2009 10:27 am
by anzagi
Hi all,

I wandering if I can get some help please, I have this PHP code to process my form, but the page doesn't do anything when submitted, now I can make edits etc to PHP but am not good enough to write it from scratch yet so dont know what the problem could be! I would be grateful of any help

Many thanks in advance

my page which holds the form is called contactus.php (this holds the form, and the processing code is on that same page)

code at the top of my page:

<?php
function isEmailAddressValid($email)
{
$result = TRUE;
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
{
$result = FALSE;
}
return $result;
}
$headers = "MIME-Version: 1.0\r";
$headers .= "Content-type: text/html; charset=iso-8859-1\r";
$headers .= "From:<".$_REQUEST['emailAddress'].">\r";
$headers .= "Reply-To:<".$_REQUEST['emailAddress'].">\r";
$headers .= "To:<>\r";
$headers .= "Cc: <>\r";
if ((isset($_REQUEST['Hiddenf5ac0663a66a75698d225b8bc6502574']) && (strcmp($_REQUEST['Hiddenf5ac0663a66a75698d225b8bc6502574'],"")==0)) && (isset($_REQUEST['Hiddenf5ac0663a66a75698d225b8bc65025741']) && (strcmp($_REQUEST['Hiddenf5ac0663a66a75698d225b8bc65025741'],"")==0)))
{
if (isset($_REQUEST['emailAddress']) && (!isEmailAddressValid($_REQUEST['emailAddress'])))
$message=$message."<div style=\"color:#FF0000;\">The e-mail address is invalid!</div>";
if (isset($_REQUEST['comments']) && (strcmp($_REQUEST['comments'],"")==0))
$message=$message."<div style=\"color:#FF0000;\">Please fill in a comment!</div>";
$message=$message.'<br/>';
if ( ((isEmailAddressValid($_REQUEST['emailAddress']))==true) && isset($_REQUEST['comments']) && (strcmp($_REQUEST['comments'],"")!=0))
{
$content=$content.'<strong>Your name </strong> '. $_REQUEST['textName'].'<br/>';
$content=$content.'<strong>Your phone number </strong> '. $_REQUEST['textName1'].'<br/>';
$content=$content.'<strong>Your email address </strong> '. $_REQUEST['textName2'].'<br/>';
$content=$content.'<strong>Brief description of enquiry/claim </strong> '. $_REQUEST['textName3'].'<br/>';
mail('myemail@adress.com','Claim/enquiry from the web site',$content,$headers);
$message='<p style=\"color:#FF0000;\">Your message has been submited!</p><br/>';
}
}
?>

form code:

<?php print $message?> <form method="post" action="contactus.php">
<div style="width:600x">
<label for="textName" class="formCreatorLabel">Your name</label><br>
<input type="text" name="textName" id="textId" class="formCreatorText" value=<?php print '"'.$_REQUEST['textName'].'"'?>/>
<br><br>

<label for="textName1" class="formCreatorLabel">Your phone number</label><br>
<input type="text" name="textName1" id="textId1" class="formCreatorText" value=<?php print '"'.$_REQUEST['textName1'].'"'?>/>
<br><br>

<label for="textName2" class="formCreatorLabel">Your email address</label><br>
<input type="text" name="textName2" id="textId2" class="formCreatorText" value=<?php print '"'.$_REQUEST['textName2'].'"'?>/>
<br><br>

<label for="textName3" class="formCreatorLabel">Brief description of enquiry/claim</label><br>
<input type="text" name="textName3" id="textId3" class="formCreatorText" value=<?php print '"'.$_REQUEST['textName3'].'"'?>/>
<br><br>
<input type="submit" value="Submit"/>
</div>
</form>

Re: Form Code Problem

Posted: Sun Feb 01, 2009 10:46 am
by jayshields
It's hard to give a perfect run down of all the problems with code formatted like that. Use the forum PHP tags for it to syntax highlight for you.

The main problem (putting aside brackets because I can't match them up when it's formatted like that!) is that your $_REQUEST array indices in most parts of the code don't match your form element names.

What is it that you're trying to achieve?

Re: Form Code Problem

Posted: Sun Feb 01, 2009 10:53 am
by anzagi
thanks for the response JayShields

Sorry if its formatted badly, this was code generated by a form generator tool so I don't know the ins and outs and I dont know what you mean about the brackets....

I just want to be able to submit a contact form from a webpage to an email address. As I understand it, this code also allows validation and spam filter, which is an added bonus. But at the moment, when I submit this page it just doesn't do anything, no validation error, know confirmation or anything

thanks again

Re: Form Code Problem

Posted: Sun Feb 01, 2009 1:56 pm
by jayshields
The first thing you should address is form element names and/or $_REQUEST array inidices.