At 22:09 26.06.2003, Scott Fletcher said:
--------------------[snip]--------------------
>I am seeing the problem now.  It seem that it had to do with the 'OR'
>statement inside the elseif statement...  I'm going to try a workaround to
>it...  As for you mentioning about the code...  It's too bad this message
>window doesn't properly display the tabs....
--------------------[snip]-------------------- 

I have a little piece of code for you that may help cleaning up your
if/elseif sequence. Not tested && may contain typos && use on your own
risk. Hope the list doesn't clutter it too much...

This multi-dimensional array should make it quite easy to manage such
situations. The main array consists of a series of sub-arrays ("structures"
containing these elements:
- 'expr' - if this evaluates to TRUE, the following checks are performed
- 'check' - an array of fieldname => error message
- 'pattern' - a pattern for sprintf to format the message

"fieldname" is assumed to be a $_REQUEST element that is checked for
emptiness. If empty, the message is issued (just as in your code) and the
function returns false. If no error occurs throughout the tests, the
function returns "Pass" (I'd prefer "true").

$test_map = array(
   array('expr'    => 'true',
         'pattern' => 'Enter [%s]',
         'check'   => array('firstname'       => 'First Name',
                            'lastname'        => 'Last Name',
                            'address'         => 'Address',
                            'city'            => 'City',
                            'state'           => 'State',
                            'zipcode'         => 'Zip Code',
                            'homephoneno'     => 'Home Phone #',
                            'dob'             => 'Date of Birth',
                            'ssn'             => 'Social Security No',
                            'dln'             => 'Driver\'s License No',
                            'occupation'      => 'Occupation',
                            'months'          => 'Residence Months',
                           ),
        ),
   array('expr'    => 'in_array(\$_REQUEST[\'rentown\'],' .
                      ' array(\'Renting\', \'Lease\',' .
                      ' \'Buying House W/Mortgage\')',
         'pattern' => 'Enter [%s]',
         'check'   => array('towhompaid'      => 'To Whom Paid',
                            'paymentaddress'  => 'Home Payment Address',
                            'paymentcity'     => 'Home Payment City',
                            'paymentstate'    => 'Home Payment State',
                            'paymentzipcode'  => 'Home Payment Zipcode',
                           ),
        ),
   array('expr'    => 'true',
         'pattern' => 'Enter [%s]',
         'check'   => array('income'          => 'Income',
                           ),
        ),
   array('expr'    => '\$_REQUEST[\'otherincome\'] > 0',
         'pattern' => 'Enter [%s]',
         'check'   => array('typeofincome'    => 'Type of Income',
                           ),
        ),
   array('expr'    => 'true',
         'pattern' => 'Enter [%s]',
         'check'   => array('bankname'        => 'Bank Name',
                           ),
        ),
   array('expr'    => '!empty(\$_REQUEST[\'Jfirstname\'])',
         'pattern' => 'Enter Cobuyer\'s [%s]',
         'check'   => array('Jlastname'       => 'Last Name',
                            'Jaddress'        => 'Address',
                            'Jcity'           => 'City',
                            'Jstate'          => 'State',
                            'Jzipcode'        => 'Zip Code',
                            'Jhomephoneno'    => 'Home Phone #',
                            'Jdob'            => 'Date of Birth',
                            'Jssn'            => 'Social Security No',
                            'Jdln'            => 'Driver\'s License No',
                            'Joccupation'     => 'Occupation',
                            'Jmonths'         => 'Residence Months',
                           ),
        ),
   array('expr'    => '!empty(\$_REQUEST[\'Jfirstname\'])' .
                      ' && in_array(\$_REQUEST[\'Jtowhompaid\'],' .
                      ' array(\'Renting\', \'Lease\', \'Buying House
W/Mortgage\'))',
         'pattern' => 'Enter Cobuyer\'s [%s]',
         'check'   => array('Jtowhompaid'     => 'To Whom Paid',
                            'Jpaymentaddress' => 'Home Payment Address',
                            'Jpaymentcity'    => 'Home Payment City',
                            'Jpaymentstate'   => 'Home Payment State',
                            'Jpaymentzipcode' => 'Home Payment Zip Code',
                           ),
        ),
   array('expr'    => '!empty(\$_REQUEST[\'Jfirstname\'])',
         'pattern' => 'Enter Cobuyer\'s [%s]',
         'check'   => array('Jincome'         => 'Income',
                            'Jtypeofincome'   => 'Type of Income',
                            'Jbankname'       => 'Bank Name',
                           ),
        ),
);

function run_test(&$map)
{
   foreach ($map as $check) {
      if (eval("return ({$check['expr']});")) {
         foreach ($check['check'] as $field => $msg) {
            if (empty($_REQUEST[$field])) {
               echo sprintf($check['pattern'], $msg);
               return false;
            }
         }
      }
   }
   return 'Pass';
}



-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



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

Reply via email to