HOW CAN I VALIDATE USING FUNCTION AND RETURN OR REDIRECT IF THE VALIDATION IS SUCCESS? PHP
Posted on 2007-03-23
I am very new to PHP and have a question regarding submitting a form after validation is successful.
My questions are:
1. HOW CAN I RETURN ERRORS AND ECHO THEM?
2. HOW CAN I ECHO "VALIDATION SUCCESS", MY CODE DOESN'T WORK PROPERLY)
3. CAN I RETURN $errors LIKE return $errors INSTEAD OF return false?
Any help in the this matter would highly be appreciated.
Lets say I have four fields on my form:
FIRST NAME | LAST NAME | EMAIL | PHONE
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
So I write this simple function:
$errors = '';
$errors = "PLEASE ENTER FIRST NAME";
// I CALL THE FUNCTIONS
if ($errors == '')
echo "VALIDATION SUCCESS";
So the form is submitted to itself:
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">