On Wed, 2004-04-07 at 19:01, Justin Patrin wrote:
> Robert Cummings wrote:
> 
> > On Wed, 2004-04-07 at 18:47, Andy B wrote:
> > 
> >>I have this very large and long if statement:
> >>if
> >> (!empty($_SESSION['add']['type'])
> >> && !empty($_SESSION['add']['start_date']
> >> && !empty($_SESSION['add']['end_date'])
> >> && !empty($_SESSION['add']['name'])
> >> && !empty($_SESSION['add']['county'])
> >> && !empty($_SESSION['add']['discription'])
> >> && !empty($_SESSION['add']['StartingDay'])
> >> && !empty($_SESSION['add']['StartingMonth'])
> >> && !empty($_SESSION['add']['StartingYear'])
> >> && !empty($_SESSION['add']['EndingDay']})
> >> && !empty($_SESSION['add']['EndingMonth'])
> >> && !empty($_SESSION['add']['EndingYear']))
> >> {//run the insert query}
> >>else
> >> {//show error since one or more fields above are blank}
> >>was wondering if there was really any way to condense that down to something
> >>any better? all fields in the form that those came from are required...
> > 
> > 
> > $errors = array();
> > foreach( $_SESSION['add'] as $key => $value )
> > {
> >     if( isempty( $value ) )
> >     {
> >         $errors[] = "You forgot to fill $key."
> >     }
> > }
> > 
> > if( count( $array ) )
> > {
> >     echo 'Hey MORON! You have the following errors:<br />';
> >     echo '<ul>'
> >         .'<li>'
> >         .implode( '</li><li>', $errors );
> >         .'</li>'
> >         .'</ul>';
> > }
> > else
> > {
> >     // Do SQL INSERT query.
> > }
> > 
> > Cheers,
> > Rob.
> 
> But if they didn't fill it in, it won't be in the array and therefore 
> won't be checked. You need to specify those keys manually.
> 
> foreach(array('type', 'start_date', etc...) as $key) {
>       if(empty($_SESSION['add'][$key])) {
>               $errors[] = $key.' not filled out';
>       }
> }

It was in the $_SESSION array, I assumed it was filled appropriately.
Also it isn't checkbox input (from what I can see) and other form fields
do provide an empty field when no content is input (if I'm not
mistaken).

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to