pixeltrace Posted May 3, 2007 Share Posted May 3, 2007 guys, i need help, i created a 1 page sendmail form and this form is inside an iframe. everything is working fine, i can fill up the form, send and i can receive my test email however after sending the email, it should normally return to its original page. its returning to its original page but the css style, placement of the form field, text is different. here is the page http://www.jobhirings.com/pd/main.php then click on the contact us button and try sending a test email to see what i mean. this is the code of my contactus.php page <!-- codes for the processing of the form --> <?php if (isset($_POST['Submit'])) { include("validate.php"); $name = $_POST['name']; $email = $_POST['email']; $contact = $_POST['contact']; $subject = $_POST['subject']; $message = $_POST['message']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($name=='' or $email=='' or $contact=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){ error("Invalid e-mail address"); } $Message = ""; $Message .= "A General Inquiry from: $name\n"; $Message .= "Contact Number: $contact\n"; $Message .= "Email Address: $email\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Message:\n"; $Message .= "$message\n"; $Message .= "\n\n"; $Header = $email; $To = "$recipient, $cc"; $Subject = "Phenom D-signs General Inquiry"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your inquiry has been sent!");window.location = "contactus.php";</script>'; } ?> <!-- end --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #6d6e71; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="480" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="36" align="right"> </td> <td colspan="2" class="title1"> <img src="images/dot.gif" width="16" height="13" /> CONTACT US </td> </tr> <tr> <td rowspan="3"> </td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td colspan="2" bgcolor="05a4dd"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> <tr> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td rowspan="12"> </td> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br></td> <td width="428" class="text1"><span class="text2"> Company Office Address </span>:</td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"><img src="images/spacer.gif" width="1" height="6" /></td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"> <span class="title2"><i>Phenom D-signs Pte Ltd</i></span> <br /> No.8 Boon Lay Way #08-06<br> 8@Trade Hub 21 Singapore 609964 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Telephone Number :</span> +65 6615 5038 </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Fax Number :</span> +65 6316 1976 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Email Address :</span> adrian(@)phenomd-signs.com.sg </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text2"> <span class="title2">General Inquiry Form</span> </td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"><form action="" method="post"><table width="382" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="10" rowspan="7"><img src="images/spacer.gif" width="10" height="1" /></td> <td width="110" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> <td width="6" rowspan="7"><img src="images/spacer.gif" width="6" height="1" /></td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> </tr> <tr> <td align="right" class="text2">name : </td> <td width="177" valign="top"><input name="name" type="text" class="field1" size="35" /></td> <td width="67" valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2">email address : </td> <td valign="top"><input name="email" type="text" class="field1" size="35" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2">contact no. : </td> <td valign="top"><input name="contact" type="text" class="field1" size="35" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" valign="top" class="text2">message : </td> <td colspan="2"><textarea name="message" cols="36" rows="5" class="field2"></textarea></td> </tr> <tr> <td> </td> <td colspan="2"><input name="Submit" type="submit" value="Send" /> <input type="hidden" name="recipient" value="adrian@phenomd-signs.com.sg" /> <input type="hidden" name="cc" value="pixeltrace@gmail.com" /> <input type=hidden value=http://www. name=redirect></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> hope you could help me with this. thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/ Share on other sites More sharing options...
Psycho Posted May 3, 2007 Share Posted May 3, 2007 Well it works for me in IE and FF. But, a few things: 1. The nav links look very different in IE and FF. 2. The email validation fails for emails with + in the username which is a valid character 3. You should add the javascript alert after the page load so the user isn't looking at a white box until the confirm 4. The flash intro ont he site is way too big. Takes too long to load. 4 Frames suck. Use a div. Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-244270 Share on other sites More sharing options...
pixeltrace Posted May 3, 2007 Author Share Posted May 3, 2007 Hi, Thanks for the reply. Do you have better ideas on how to solve this? where will i place the javascript? what codes will i add so the "+" in the username can be allowed? hope you could share me the codes. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-244425 Share on other sites More sharing options...
Psycho Posted May 3, 2007 Share Posted May 3, 2007 Add the javascript as a function and add an onload trigger. Here is the code I use for email validation: function validEmail(field) { emailRegEx = /^([\w\+-])+([\.]?[\w\+-])*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9])*\.([a-zA-Z]{2,4})$/ return (emailRegEx.test(field.value)); } Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-244635 Share on other sites More sharing options...
pixeltrace Posted May 4, 2007 Author Share Posted May 4, 2007 hi, i tried the email codes that you used but its still not accepting emails with "+" in the username how will i do this correctly? sorry i am not yet very familair with functions. hope you could help me with it. below is my codes for the contactus.php page <!-- codes for the processing of the form --> <?php if (isset($_POST['Submit'])) { include("validate.php"); $name = $_POST['name']; $email = $_POST['email']; $contact = $_POST['contact']; $subject = $_POST['subject']; $message = $_POST['message']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($name=='' or $email=='' or $contact=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } if (!eregi("/^([\w\+-])+([\.]?[\w\+-])*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9])*\.([a-zA-Z]{2,4})$/", $email)){ error("Invalid e-mail address"); } $Message = ""; $Message .= "A General Inquiry from: $name\n"; $Message .= "Contact Number: $contact\n"; $Message .= "Email Address: $email\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Message:\n"; $Message .= "$message\n"; $Message .= "\n\n"; $Header = $email; $To = "$recipient, $cc"; $Subject = "Phenom D-signs General Inquiry"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your inquiry has been sent!");top.location = "main.php?url=contactus.php";</script>'; } ?> <!-- end --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #6d6e71; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="480" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="36" align="right"> </td> <td colspan="2" class="title1"> <img src="images/dot.gif" width="16" height="13" /> CONTACT US </td> </tr> <tr> <td rowspan="3"> </td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td colspan="2" bgcolor="05a4dd"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> <tr> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td rowspan="12"> </td> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br></td> <td width="428" class="text1"><span class="text2"> Company Office Address </span>:</td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"><img src="images/spacer.gif" width="1" height="6" /></td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"> <span class="title2"><i>Phenom D-signs Pte Ltd</i></span> <br /> No.8 Boon Lay Way #08-06<br> 8@Trade Hub 21 Singapore 609964 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Telephone Number :</span> +65 6615 5038 </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Fax Number :</span> +65 6316 1976 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Email Address :</span> adrian(@)phenomd-signs.com.sg </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text2"> <span class="title2">General Inquiry Form</span> </td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"><form action="" method="post"><table width="382" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="10" rowspan="7"><img src="images/spacer.gif" width="10" height="1" /></td> <td width="110" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> <td width="6" rowspan="7"><img src="images/spacer.gif" width="6" height="1" /></td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> </tr> <tr> <td align="right" class="text2">name : </td> <td width="177" valign="top"><input name="name" type="text" class="field1" size="35" /></td> <td width="67" valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2">email address : </td> <td valign="top"><input name="email" type="text" class="field1" size="35" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2">contact no. : </td> <td valign="top"><input name="contact" type="text" class="field1" size="35" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" valign="top" class="text2">message : </td> <td colspan="2"><textarea name="message" cols="36" rows="5" class="field2"></textarea></td> </tr> <tr> <td> </td> <td colspan="2"><input name="Submit" type="submit" value="Send" /> <input type="hidden" name="recipient" value="pixeltrace@gmail.com" /> <input type="hidden" name="cc" value="pixeltrace@gmail.com" /> <input type=hidden value=http://www. name=redirect></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-245480 Share on other sites More sharing options...
Psycho Posted May 4, 2007 Share Posted May 4, 2007 The code I provided is a javascript function, not PHP. however, ideally you should be doing validation on the server side as well. Here is how you could implement the client-side test: <html> <head> <script> function validEmail(email) { emailRegEx = /^([\w\+-])+([\.]?[\w\+-])*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9])*\.([a-zA-Z]{2,4})$/ return (emailRegEx.test(email)); } function checkEmail(field) { if (field.value && !validEmail(field.value)) { alert("That email is not valid."); field.select(); field.focus(); } } </script> </head> <body> <input type="text" name="email" onchange="checkEmail(this);"> </body> </html> What is error(0 for in your code. I *think* you are using it to create a javascript error message. That is a very poor implementation in my opinion. Using server-side validation to create a client-side error message reduces the benefits of server-side validation. If a user does not have javascript enabled they will not see the error message. I typically use client-side code to do initial validation to give the user a chance to correct before submitting. But, I also do server-side validation as a backup - because it is possible to submit code NOT through the UI. Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-245561 Share on other sites More sharing options...
pixeltrace Posted May 5, 2007 Author Share Posted May 5, 2007 yes, the error() is calling out the msg function (i think) from the validate.php this is the code for the validate.php <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> do you think we can just add here the javascript code that you gave me? if ever that will be the case, whats the proper way to do it? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-245986 Share on other sites More sharing options...
pixeltrace Posted May 5, 2007 Author Share Posted May 5, 2007 hi mjdamato, what will the codes be? as well as for the client side? i agree with you on the javascript and i think your ideas is better but i honestly dont know how to implement it. hope you could help me with it. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-245993 Share on other sites More sharing options...
Psycho Posted May 6, 2007 Share Posted May 6, 2007 OK, I ended up woking on this a LOT more than I had planned. The regex expression I was using in javascript needed a litle finessing to convert to PHP and in the process I ended up improving my regex expression. I rewrote your page so that all the validation would be servere-side and the error messages would appear within the page instead of using javascript alerts. You could also use javascript to validate before submitting, but using javascript to display errors found ont he server-side is bad in my opinion. In case you need to modify the email validation here is how it works: ^[\+a-z0-9_-]+([\.][\+a-z0-9_-]+)*@([a-z0-9]+[\.-])*[a-z0-9]+\.[a-z]{2,3}$ The first part ^[\+a-z0-9_-]+ includes all alpha-numeric characters as well as '+', '_' and '-'. They must be present 1 or more times. The second part ([\.][\+a-z0-9_-]+)* allows for additional characters 'sections' in the username and requires that the section begins with a single period and then con contain one or more of the same characters noted above. However the * indicates that these 'sections' may appear 0 or more times. Then the @ sign is required. The next section ([a-z0-9]+[\.-])* is for subdomains. They must include 1 or more alpha-numeric characters and end with a single period (or a minus sign). The subdomains may exist 0 or more times. Ok, the minus sign is not for subdomins, but it may not start or end a domain or subdomain so I treat it the same as a period. Then the domain [a-z0-9]+ (or last part of a domain following the minus sign) must include 1 or more alpha-numeric characters. Then there must be a period followed by 2-3 alpha characters for the TLD (top level domain, .com, .net, etc.) <?php if (isset($_POST['Submit'])) { $name = $_POST['name']; $email = $_POST['email']; $contact = $_POST['contact']; $subject = $_POST['subject']; $message = $_POST['message']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; $error = false; if ($name=='' or $email=='' or $contact=='') { $error = 'Some required fields are blank.<br>Please fill them in and try again.'; } $regEx = "^[\+a-z0-9_-]+([\.][\+a-z0-9_-]+)*@([a-z0-9]+[\.-])*[a-z0-9]+\.[a-z]{2,3}$"; if (!eregi($regEx, $email)) { $error = 'Invalid e-mail address'; } if (!$error) { $Msg = "A General Inquiry from: $name\n"; $Msg .= "Contact Number: $contact\n"; $Msg .= "Email Address: $email\n"; $Msg .= "IP address: " . getenv("REMOTE_ADDR") . "\n"; $Msg .= "\n\n"; $Msg .= "Message:\n"; $Msg .= "$message\n\n"; $Header = "From: $email"; $To = "$recipient, $cc"; $Subject = "Phenom D-signs General Inquiry"; if (mail($To, $Subject, $msg, $Header)) { //Change this to a redirect to a page confirming message was sent echo "Your message was sent."; exit; } else { //Change this to a redirect to a page saying email was not sent echo "There was an error sending your message."; exit; } } } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #6d6e71; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="480" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="36" align="right"> </td> <td colspan="2" class="title1"><img src="images/dot.gif" width="16" height="13" /> CONTACT US </td> </tr> <tr> <td rowspan="3"> </td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td colspan="2" bgcolor="05a4dd"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> <tr> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td rowspan="12"> </td> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br></td> <td width="428" class="text1"><span class="text2"> Company Office Address </span>:</td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"><img src="images/spacer.gif" width="1" height="6" /></td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"> <span class="title2"><i>Phenom D-signs Pte Ltd</i></span> <br /> No.8 Boon Lay Way #08-06<br> 8@Trade Hub 21 Singapore 609964 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"> </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Telephone Number:</span> +65 6615 5038 </td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Fax Number:</span> +65 6316 1976 </td> </tr> <tr> <td colspan="2" align="right" valign="top" class="text1"><img src="images/spacer.gif" width="1" height="10" /></td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text1"> <span class="text2">Email Address :</span> adrian(@)phenomd-signs.com.sg </td> </tr> <tr> <td colspan="2" align="center" valign="top" class="text1" style="color:#ffffff;"><br><br> <?=$error?> <br><br></td> </tr> <tr> <td width="16" align="right" class="text1"><img src="images/arrow.png" width="10" height="9" /><br /></td> <td valign="top" class="text2"> <span class="title2">General Inquiry Form</span> </td> </tr> <tr> <td width="16" align="right" valign="top" class="text1"> </td> <td valign="top" class="text1"><form action="" method="post"><table width="382" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="10" rowspan="7"><img src="images/spacer.gif" width="10" height="1" /></td> <td width="110" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> <td width="6" rowspan="7"><img src="images/spacer.gif" width="6" height="1" /></td> <td colspan="2" valign="top"><img src="images/spacer.gif" width="1" height="6"></td> </tr> <tr> <td align="right" class="text2">name: </td> <td width="177" valign="top"><input name="name" type="text" class="field1" size="35" value="<?=$name?>" /></td> <td width="67" valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2" nowrap>email address: </td> <td valign="top"><input name="email" type="text" class="field1" size="35" value="<?=$email?>" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" class="text2" nowrap>contact no.: </td> <td valign="top"><input name="contact" type="text" class="field1" size="35" value="<?=$contact?>" /></td> <td valign="top"> <span class="text3">*</span></td> </tr> <tr> <td align="right" valign="top" class="text2">message: </td> <td colspan="2"><textarea name="message" cols="36" rows="5" class="field2"><?=$message?></textarea></td> </tr> <tr> <td> </td> <td colspan="2"><input name="Submit" type="submit" value="Send" /> <input type="hidden" name="recipient" value="pixeltrace@gmail.com" /> <input type="hidden" name="cc" value="pixeltrace@gmail.com" /> <input type=hidden value=http://www. name=redirect></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/49773-help-on-my-formmail/#findComment-246428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.