echo print to web page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amarkabove
Forum Newbie
Posts: 1
Joined: Thu Mar 06, 2008 6:22 pm

echo print to web page

Post by amarkabove »

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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: echo print to web page

Post by yacahuma »

what is supposed to happen after the process form?

Where is the process form code?
Post Reply