Error Checking for at least one value selected in multi-value list before submission

5 posts by 3 authors in: Forums > CMS Builder
Last Post: January 14, 2016   (RSS)

Hi All,

I need to do an error check to make sure that at least one search criteria value has been selected in a multi-value pull down list (called provider_state (as in NY, CT, VT etc.)) before form submission.

I've tried using the functions in_array and also isset, and I can’t seem to get it right.

Any ideas? (Or maybe there’s a much simpler approach...)

Thanks,

Jerry Kornbluth

Here’s what I’m using at the top of my page.

<?php $errorsAndAlerts = ""; ?>
<?php if (@$_REQUEST['save'] == 1) {
    $string = '[practice_state_keyword]';
$array = $_REQUEST;
if ( !in_array( $string, $array ) )
{
   $errorsAndAlerts .= "You'll need to choose at least a State and re-submit your search to continue<br/>\n";

 // on success
 
    if (!$errorsAndAlerts) {
 
      $errorsAndAlerts = "Thanks, your search can continue!<br/>\n";
    }
 }    
    
}?>



I also tried:

<?php $errorsAndAlerts = ""; ?>
<?php if (@$_REQUEST['save'] == 1) {
   
$var = '$_REQUEST[practice_state_keyword]';

if ( !isset($var ) )
{
   $errorsAndAlerts .= "You'll need to choose at least a State and re-submit your search to continue<br/>\n";

 // on success
 
    if (!$errorsAndAlerts) {
 
      $errorsAndAlerts = "Thanks, we've updated your profile!<br/>\n";
    }
 }    
    
}?>


And here is the trimmed version of my form

<table>
    <form method="post" action="">
      <input type="hidden" name="save" value="1" />
      <tr>
        <td >State:</td>
        <td>
<select name = "practice_state_keyword" multiple>
           
            <?php foreach (getListOptions('accounts', 'practice_state') as $value => $label1): ?>
            <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['practice_state']);?>> <?php echo $label1; ?></option>
            <?php endforeach ?>
          </select></td>
      </tr>
</table>


When a practice_state_keyword is selected showme( $_REQUEST ) displays:

Array
( [save] => 1
[practice_state_keyword] => 7
)


and when it’s not (or before submission) it displays:

Array
(
)

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - January 13, 2016

Hi Jerry,

Just wanted to check, is this what you are working with Ross on through consulting?

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Hi Damon,

Thanks for looking at this.

No, it's not the same. We're working on passing selected values.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Thanks Greg,

I'm out of town for a few days bit i'll make the changes as soon as I get back to the office.

Appreciate your help

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php