Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermining if other <option> was selected, or if default "Select one..." with blank value was submitted
    primarykey
    data
    text
    <p>I am adding a sort by option to my search page. I am using two select form input type, one for the field to order by, and one for ASC/DESC. I have the first option with value="" and text "Select one...".</p> <pre><code>&lt;label for="sort[order_by_field]"&gt;Field&lt;/label&gt;&lt;select name="sort[order_by_field]" id="combobox"&gt; &lt;option value=""&gt;Select one...&lt;/option&gt; &lt;optgroup label="---"&gt; &lt;option value="finding_incident_number"&lt;?php echo ($field == 'finding_incident_number' ? ' selected="selected"': false); ?&gt;&gt;Incident #&lt;/option&gt; &lt;option value="finding_violation_type"&lt;?php echo ($field == 'finding_violation_type' ? ' selected="selected"': false); ?&gt;&gt;Finding&lt;/option&gt; &lt;label for="sort[order_by_direction]"&gt;Direction&lt;/label&gt; &lt;select name="sort[order_by_direction]"&gt; &lt;option&gt;Select one...&lt;/option&gt; &lt;option value="ASC"&lt;?php echo ($dir == 'ASC' ? ' selected="selected"': false); ?&gt;&gt;Ascending&lt;/option&gt; &lt;option value="DESC"&lt;?php echo ($dir == 'DESC' ? ' selected="selected"': false); ?&gt;&gt;Descending&lt;/option&gt; &lt;/select&gt; </code></pre> <p>After submitting my form, I check if isset($_POST['sort']). It is set. I also check for !empty. It is always !empty. I want to know if the user actually made a selection. Is there a way to set this up so that I don't have to check on individual array values, i.e. isset($_POST['sort']['order_by_field'])? I would like to have a dynamic number of addable/removable sort by fields in the future.</p> <p>I suppose I could use an optiongrp label, but then that wouldn't be semantic markup would it? I guess it would work though.</p> <p>From a broader perspective, is putting "Select One..." a good practice for a form dropdown?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload