S
S
sivabur2015-11-25 21:55:49
PHP
sivabur, 2015-11-25 21:55:49

What's the best way to template output in a select tag?

<select name="StandardProductIDType" id="StandardProductIDType" class="TxtField">
                  <option value="None">keine</option>
                  <option value="ASIN">ASIN (Amazon)</option>
                  <option value="EAN" selected="selected">EAN</option>
                  <option value="GTIN">GTIN</option>
                  <option value="ISBN">ISBN</option>
                  <option value="UPC">UPC</option>
                </select>

That is, the options are known in advance, but one of them is selected when outputting which one I get from the base.
How competently in the View (or the view template) is everything to be presented harmoniously.
And it's not a simfony)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2015-11-25
@sivabur

<?php

$results = array(
    array(
        'value' => 'None',
        'name' => 'keine',
        'selected' => false),
    array(
        'value' => 'ASIN',
        'name' => 'ASIN (Amazon)',
        'selected' => false),
    array(
        'value' => 'EAN',
        'name' => 'EAN',
        'selected' => true),
    array(
        'value' => 'GTIN',
        'name' => 'GTIN',
        'selected' => false),
    array(
        'value' => 'ISBN',
        'name' => 'ISBN',
        'selected' => false),
    array(
        'value' => 'UPC',
        'name' => 'UPC',
        'selected' => false),
    );
?>

<select name="StandardProductIDType" id="StandardProductIDType" class="TxtField">
<? foreach ($results as $result): ?>
<option value="<?= $result['value']; ?>" <?= ($result['selected'] ?
'selected="selected"' : null); ?>><?= $result['name']; ?></option>
<? endforeach; ?>
</select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question