I am working on buiding a tell a friend script and it works, but before any information is added it's echoing an error.
I'm working from a previous script that was just a contact form.
Here is the original section of code...
...and this is what I've changed it to (vars were all changed in my form so no issue there.PHP Code:if (isset($c['submit'])) {
if (empty($c['name']) || empty($c['email']) || empty($c['comments'])) {
$error_msg .= "Name, Email, and Question / Comment are required fields. \n";
} elseif (strlen($c['name']) > 25) {
$error_msg .= "The name field is limited at 25 characters. Your first name will do! \n";
} elseif (!ereg("^[A-Za-z' -]", $c['name'])) {
$error_msg .= "The name field must not contain special characters. \n";
} elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($c['email']))) {
$error_msg .= "That is not a valid e-mail address. \n";
}
if ($error_msg == NULL) {
$show_form = false;
if (!empty($c['url']) && !ereg("^(http|https)", $c['url'])) {
$c['url'] = "http://" . $c['url'];
}
The modified code gets the job done but when you view the form before anything is added it shows "Your friend's name must not contain special characters."PHP Code:if (isset($c['submit'])) {
if (empty($c['y_name']) || empty($c['y_email']) || empty($c['f_name']) || empty($c['f_email']) || empty($c['comments'])) {
$error_msg .= "All fields are required, please fill them in. \n";
## YOUR INFO CHECK ##
} elseif (strlen($c['y_name']) > 25) {
$error_msg .= "Please enter your name. \n";
} elseif (!ereg("^[A-Za-z' -]", $c['y_name'])) {
$error_msg .= "Your name must not contain special characters. \n";
} elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($c['y_email']))) {
$error_msg .= "Your email address isn't valid. \n";
}
## FRIEND INFO CHECK ##
} elseif (strlen($c['f_name']) > 25) {
$error_msg .= "Please enter your friend's name. \n";
} elseif (!ereg("^[A-Za-z' -]", $c['f_name'])) {
$error_msg .= "Your friend's name must not contain special characters. \n";
} elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($c['f_email']))) {
$error_msg .= "Your friend's email address isn't valid. \n";
}
if ($error_msg == NULL) {
$show_form = false;
if (!empty($c['url']) && !ereg("^(http|https)", $c['url'])) {
$c['url'] = "http://" . $c['url'];
}
I'll post more code if needed but am trying to avoid posting a long section of code. Maybe someone will spot something in the above that I am overlooking. Thank you



Reply With Quote
Bookmarks