I got an ajax submitting form source code, and learning it right, I found the return errors are all in a big square. I want to separate errors to where they belong to.
then I can simply add something like following code
<?php if($_session('errorarray'): ?>
<span class="errorclass"><?php echo $errorarray['phone']; ?></span>
<?php endif; ?>
here is validation php code, (I have 5 items need to be checked)
$error = array();
if(!check('name'))
$error[]='too short!';
else if(validate_name($_POST['name']))
$error[]='letters please!';
..........
if(checkphone($_POST['phone'])){
$error[]="Please enter a valid phone number";
}
here is the code return to $_Session
if(count($error))
{
if($_POST['ajax'])
{
echo '-1';
}
else if($_SERVER['HTTP_REFERER'])
{
**$_SESSION['errorarray'] = array ($error);** // possible?
$_SESSION['post']=$_POST;
header('Location: '.$_SERVER['HTTP_REFERER']);
}
exit;
}
Sorry I am very new to php. Hope my expression is not too hard to understand.
Many thanks in advance.
You can just set
$_SESSION['errorarray'] = $error;Then in your view, you can do something like<span class="errorclass"><?php foreach ($_SESSION['errorarray'] as $err) { echo $err; } ?></span>Sorry, your question is a bit unclear, if you provide more details we could probably give you a better answer.