Hello All,
I am a beginner in PHP and need to do a small application(few pages). I have a page in which I am few textbox like like FirstName, LastName, ComboBox for Birthdate. Now I have to validate this all the control and need to show error message as a listbox on the top of page or below the form.
Can you please help me how to do it. I have used Error Message list in Asp.net 2005 as i used to code in .Net and am still doing it.
Waiting for your reply.
Thanks for the help in advance.
Validations on Page
Moderator: General Moderators
Re: Validations on Page
As you validate the input, you can collect error messages in an array.
Then you can format the errors for display on your page.
Edit: This post was recovered from search engine cache.
Code: Select all
<?php
$errors = array();
if (strlen($_POST['comment']) > 200)
{
$errors[] = 'You comment should be 200 characters or less.';
}
if (0 < preg_match('/[^a-z0-9]/i', $_POST['username']))
{
$errors[] = 'Your user name can only contain alpha-numeric characters.';
}
?>Code: Select all
<?php
if (!empty($errors))
{
echo '<ul>';
foreach ($errors as $error)
{
echo "<li>$error</li>";
}
echo '</ul>';
}
?>