Friday, 15 August 2014

forms - How to process select box in PHP when you want to process the actual '' and not the 'value' attribute? -



forms - How to process select box in PHP when you want to process the actual '<option>' and not the 'value' attribute? -

<span> kamertype :</span> <select class="autowidthselect" required area-required="true" name="prijskamertype" onchange="calculateprice()" id="prijskamertype"> <option selected="selected" value="">selecteer kamertype</option> <option value="295">kraaiennest</option> <option value="395">kajuit</option> <option value="495">kapiteinshut</option> </select>

when process above php code below, shows me content defined in 'value' attribute, in case prices. want show content defined in <option> tag (kraaiennest, kajuit, kapiteinshut). how accomplish that?

(i can not alter values, because of calculation of total cost @ end of form)

<?php $prijskamertype = $_post ['prijskamertype']; echo $prijskamertype.' type'; ?>

edit:

i have created array , drop-down list it:

<?php $optionskamertype = array(); $optionskamertype[""] = "selecteer kamertype"; $optionskamertype["295"] = "kraaiennest"; $optionskamertype["395"] = "kajuit"; $optionskamertype["495"] = "kapiteinshut"; ?>

html-code:

<span> kamertype :</span> <select class="autowidthselect" required area-required="true" name="prijskamertype" onchange="calculateprice()" id="prijskamertype"> <?php foreach($optionskamertype $key => $value) { echo '<option value="'. $key .'" label="'. $value .'">'.$value.'</option>'; } ?> </select>

what have now?

this isn't php, it's how html forms work: thing sent server browser content of value attribute. (or, if there isn't one, content of alternative tag, doesn't help here because still 1 value.)

what can do, though, have array in php code has values , labels of options. can utilize create drop-down in first place, , when form submitted this:

$label = $option_list[ $_post['whatever'] ];

php forms drop-down-menu form-processing

No comments:

Post a Comment