
Claude 🤖
New Members-
Posts
6 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
Claude 🤖's Achievements

Newbie (1/5)
0
Reputation
-
Here's what I've got now, and it's still getting a syntax error on the last line... <?php if($_POST['submit']) { // only checking for empty fields, regexp can do a lot more. $error = ""; if( $_POST['name'] == "") { $error .= "<br />- Name field is empty."; } if( $_POST['phone'] == "") { $error .= "<br />- Phone field is empty."; } if( $_POST['email'] == "") { $error .= "<br />- Email field is empty."; } $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "New Lead!!!"; $name = Trim(stripslashes($_POST['name'])); $phone = Trim(stripslashes($_POST['phone'])); $email = Trim(stripslashes($_POST['email'])); $message = Trim(stripslashes($_POST['message'])); if($error == "") { // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Phone Number: "; $Body .= $phone; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; // send email echo "OK"; }else{ echo<<<END <html> <head></head> <body> <form action="form.php" method="POST"> Name: <input type="text" name="name" value="$name"><br /> Phone Number: <input type="text" name="phone" value="$phone"><br /> Email: <input type="text" name="email" value="$email"><br /> Message: <input type="text" name="message" value="$message"><br /> <input type="submit" name="submit"> <p>$error</p> </form> </body> </html> END; } ?> Any idea where it's going awry?
-
Denno, Thanks for the clarification. revraz, Thanks for the heads up on the typos. Even after fixing those it still didn't make the fields mandatory. It would allow me to submit the form and take me through to the correct follow up page, but I can still submit it blank. Abuda, I also tried yours and it didn't quite work either. I'd hit submit and it would take me to another page solely dedicated to the contact form, then when I filled that out it would pop up as a hosting error with the page not found. I combined what you suggested with the original to get this: <?php if($_POST['submit']) { // only checking for empty fields, regexp can do a lot more. $error = ""; if( $_POST['name'] == "") { $error .= "<br />- Name field is empty."; } if( $_POST['phone'] == "") { $error .= "<br />- Phone field is empty."; } if( $_POST['email'] == "") { $error .= "<br />- Email field is empty."; } $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "New Lead!!!"; $name = Trim(stripslashes($_POST['name'])); $phone = Trim(stripslashes($_POST['phone'])); $email = Trim(stripslashes($_POST['email'])); $message = Trim(stripslashes($_POST['message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone Number: "; $Body .= $Phone_Number; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success) {//&& ($Phone_Number != "" || $Email != "") { print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> and it tells me Parse error: syntax error, unexpected $end on the last line of it. MOD Edit: . . . tags added.
-
First two lines here are useless. (!$validationOK) will never return TRUE since you already set validationOK to TRUE one line earlier. Am I imagining this? Abuda, I have those three since I have it sending to three separate email addresses. The original code works, I just want to make the Name, Phone, and Email mandatory. Denno, I tried what you suggested. Looks like this: <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "New Lead!!!"; $Name = Trim(stripslashes($_POST['Name'])); $Phone_Number = Trim(stripslashes($_POST['Phone_Number'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); function validate_form ( ) { valid = true; if ( 'Name" == "" ) { alert ( "Please Enter Your Name." ); valid = false; } else if ( 'Phone_Number' == "" ) { alert ( "Please Enter Your Phone Number." ); valid = false; } else if ( 'Email" == "" ) { alert ( "Please Enter Your Email" ); valid = false; } return valid; } // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone Number: "; $Body .= $Phone_Number; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success) {//&& ($Phone_Number != "" || $Email != "") { print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> I'm getting an error message on line 14 for an unexpected "=". I'm pretty new to PHP and my web guy fell off the face of the earth, so I've been trying to tackle this myself. Any suggestions on where to tweak? Do I need the validate form and the validate, or is that redundant?
-
So here's the new code I input: <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "New Lead!!!"; $Name = check_imput($_POST['Name'],"Enter Your Name"); $Phone_Number = check_imput($_POST['Phone_Number'],"Enter Your Phone Number"); $Email = check_imput($_POST['Email'],"Enter Your Email"); $Message = check_imput($_POST['Message']); <?php function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { die($problem); } return $data; } ?> // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm/">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone Number: "; $Body .= $Phone_Number; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success) {//&& ($Phone_Number != "" || $Email != "") { print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php/">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm/">"; } ?> and from there I get a: Parse error: syntax error, unexpected '<' on line 13. Remove that and get: Parse error: syntax error, unexpected '?' on line 13. Remove that and get: Parse error: syntax error, unexpected T_FUNCTION on line 14 I'm gonna try the original with Denno's java
-
Denno, I'd been trying something similar to what you suggested. I'll give it a go again. The code you supplied is a bit different, so maybe it'll work out the kinks.
-
I've been trying to make my contact form engine mandatory for the name, phone number and email fields, but when I upload it on the ftp and test it, I keep getting errors. Here's the code I have that is working without the fields being mandatory: <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "New Lead!!!"; $Name = Trim(stripslashes($_POST['Name'])); $Phone_Number = Trim(stripslashes($_POST['Phone_Number'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone Number: "; $Body .= $Phone_Number; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success) {//&& ($Phone_Number != "" || $Email != "") { print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> I would like it to return something that says: "Enter Your Name/Phone Number/Email" corresponding to the appropriate field they didn't fill out. Thanks for any input you can provide!