Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Form input select multiple only submits one value, even if more selected?
  • I am using input select with attribute multiple="multiple" like this
    <select size="10" multiple="multiple" class="span6" id="form_related_articles" name="related_articles">
      <optgroup label="Misija evrovizija" class="fontmisija">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
      </optgroup>
      <optgroup label="Festivali" class="fontfest">
        <option value="5">Five</option>
        <option value="6">Six</option>
        <option value="7">Seven</option>
      </optgroup>
    </select>
    

    when submitting form then Input::post('related_articles') always only has the last selected value... ? Isn't this suppose to submit array of selected values?
  • HTML nor the browser will make "related_articles" an array, thus multiple values will be posted like this in your example:
    related_articles=1&related_articles=2&related_articles=3

    The problem is that each new value will overwrite the earlier, thus leaving only the last selected value. Rename the form attribute to "related_articles[]" and it'll be like this when posted:
    related_articles[]=1&related;_articles[]=2&related;_articles[]=3

    Giving you array(1,2,3) instead of just the last value.
  • Awesome Jelmer, thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion