php - Is it possible to filter an array of select values from a form? -



php - Is it possible to filter an array of select values from a form? -

say have form:

<form method="post"> <select name="s[]" multiple="multiple"> <option value="12345678">one</option> <option value="a7e6b65e">two</option> <option value="ad2445f7">three</option> <option value="998d64fe">four</option> </select> <input type="submit" value="go"> </form>

once form submitted, can utilize 1 of filters functions create sure info ok? first thought filter_input_array, don't think that's it.

the way see, first check if have array, cycle through values:

$s_clean = array(); if (isset($_post['s']) && is_array($_post['s'])) { foreach ($_post['s'] $o) { $s_clean[] = filter_var($o, filter_validate_regexp, array('options' => array('regexp' => '/^[0-9a-f]{8}$/'))); } }

is there simpler way?

you should have al possible alternative values available in array. validate if options retrieved @ post defined in array.

if (!in_array($o, $options)) { //throw validation error here }

php

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -