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)

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

Hi Jerry,

I've taken a look over the code, I noticed a couple of things that need changing to get it running.

The HTML look good, you just need to add a couple of square brackets to the end of the name to get it to send multiple values:

<table>
  <?php echo $errorsAndAlerts; ?>
  <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('blog', 'category') as $value => $label): ?>
            <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['practice_state']);?>> <?php echo $label; ?></option>
          <?php endforeach ?>
        </select>
      </td>
    </tr>
    <input type="submit" name="go" value="go">
  </form>
</table>

Then you can check that they've selected at least one item by checking that something is set in the value practice_state_keyword:

  $errorsAndAlerts = "";
  if(@$_REQUEST['save']){

    if(!@$_REQUEST['practice_state_keyword']) { $errorsAndAlerts .= "You must select at least one state!<br>\r\n"; }

    if(!$errorsAndAlerts){
      //NO ERRORS
    }
  }

So the above code checks that we can find the save variable, and if we can, we then check that something is set in the practice_state_keyword variable. 

Let me know if you have any questions!

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

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