echo print to web page
Posted: Thu Mar 06, 2008 6:28 pm
i have a form that has required fields. when the form is submitted everything works right except when the error_text is to be printed to the web page. if i use echo, it prints the error message at the very top of the page. if i don't use echo nothing prints to the page.
if ($_POST['_submit_check']) {
if ($form_errors = validate_form()){
show_form($form_errors);
}else{
process_form();
}
}else {
show_form();
}
function show_form($errors = '') {
if ($errors) {
$error_text = '<p> These fields are required.<br>';
$error_text .= implode('<br>',$errors);
$error_text .= '</p>';
}else{
$error_text = '';
}
}
function validate_form() {
$errors = array();
if (! strlen(trim($_POST['CompanyName']))) {
$errors[] = 'Please enter your Company Name';
}
if (! strlen(trim($_POST['CompanyContact']))) {
$errors[] = 'Please enter the Company Contact';
}
if (! strlen(trim($_POST['PhoneNumber']))) {
$errors[] = 'Please enter the Contact Phone Number';
}
return $errors;
}
here is the code in the web page
<p><?php print $error_text; ?></p> this produces nothing
if ($_POST['_submit_check']) {
if ($form_errors = validate_form()){
show_form($form_errors);
}else{
process_form();
}
}else {
show_form();
}
function show_form($errors = '') {
if ($errors) {
$error_text = '<p> These fields are required.<br>';
$error_text .= implode('<br>',$errors);
$error_text .= '</p>';
}else{
$error_text = '';
}
}
function validate_form() {
$errors = array();
if (! strlen(trim($_POST['CompanyName']))) {
$errors[] = 'Please enter your Company Name';
}
if (! strlen(trim($_POST['CompanyContact']))) {
$errors[] = 'Please enter the Company Contact';
}
if (! strlen(trim($_POST['PhoneNumber']))) {
$errors[] = 'Please enter the Contact Phone Number';
}
return $errors;
}
here is the code in the web page
<p><?php print $error_text; ?></p> this produces nothing