2

I have a custom field called "newsletter", I've mapped this to order_custom2 from within the store settings and used the following code:

  <div class="control-group {if error:order_custom2}error{/if}">
    <label class="control-label" for="order_custom2">Newsletter</label>
    <div class="controls">
      {field:order_custom2} {error:order_custom2}
    </div>
  </div>

However it's outputting the field as a input text box rather than a select box (it was set as a select box in the member preferences) and I can't work out how to change it from a text field to a select box, any ideas?

3

The shortcut tags provide a quick and easy way to add the field to the page but by default this will output as an input field. You do however have full control over the HTML elements and an output any form component you wish to use by simply ensuring the name attribute matches the name of the field. For example:

<div class="control-group {if error:order_custom2}error{/if}">
  <label class="control-label" for="order_custom2">Newsletter</label>
  <div class="controls">
    <select name="order_custom2" id="order_custom2" >
      <option value="yes">Subscribe</option>
      <option value="no">Don't Subscribe</option>
    </select>
    {error:order_custom2}
  </div>
</div>

Will output a select box with whatever options you wish to provide. The name attribute ensures the selected value will be saved to order_custom2.

1
  • Was about to ask almost exactly the same question. Brilliant.
    – JKM
    Jan 29 '14 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.