Concrete5.7.5.2 - How to set selected option in select box?

Permalink
I use the following code for a select box:
$form->select($name, $options, $value, $tagAttributes)

But I can't find any information where I can set one of my options to 'selected' property, for example:
<option value="http://mysite.com" selected>My Site</option>


Anyone know? Thank you.

linuxoid
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi linuxoid,

The Form widget will add "selected="selected"" to the option element that is true.

Example:
<div class="form-group">
    <?php echo $form->label('select_example', t('Select')); ?>
    <br>
    <?php echo $form->select('select_example', array('acorn' => t('acorn'), 'lemon' => t('lemon'), 'turnip' => t('turnip')), $select_example, array('style' => 'width: 125px;')); ?>
    <br>
</div>

When you first use the select widget, $select_example has no value.
<select id="select_example" name="select_example" style="width: 125px;" class="form-control">
    <option value="acorn">acorn</option>
    <option value="lemon">lemon</option>
    <option value="turnip">turnip</option>
</select>

Selecting "turnip" from the select, then saving. The value of $select_example is "turnip".
<select id="select_example" name="select_example" style="width: 125px;" ccm-passed-value="turnip" class="form-control">
    <option value="acorn">acorn</option>
    <option value="lemon">lemon</option>
    <option value="turnip" selected="selected">turnip</option>
</select>
linuxoid replied on at Permalink Reply
linuxoid
Thank you for your reply.

From the w3schools website:http://www.w3schools.com/tags/att_option_selected.asp...

<option selected>

Differences Between HTML 4.01 and HTML5
NONE.

Differences Between HTML and XHTML
In XHTML, attribute minimization is forbidden, and the selected attribute must be defined as <option selected="selected">.

Which is the correct way in C5.7?