Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Form::checkboxes method
  • Hi Multiple checkboxes is a pattern I use a lot (ie for tagging) and noticed there was nothing like it in Fuel. Think this could go into Core http://scrp.at/vN Example output from linked code.
    <label><input name="tags[]" value="1" type="checkbox" /> Aggressive</label>
     <label><input name="tags[]" value="2" type="checkbox" /> Calm</label>
     <label><input name="tags[]" value="3" type="checkbox" /> Cheerful</label>
     <label><input name="tags[]" value="4" type="checkbox" /> Confident</label>
     <label><input name="tags[]" value="5" type="checkbox" /> Dark</label>
     <label><input name="tags[]" value="6" type="checkbox" /> Dramatic</label>
     <label><input name="tags[]" value="7" type="checkbox" /> Edgy</label>
     <label><input name="tags[]" value="8" type="checkbox" /> Energetic</label>
     <label><input name="tags[]" value="9" type="checkbox" /> Hopeful</label>
     <label><input name="tags[]" value="10" type="checkbox" /> Laid back</label>
     <label><input name="tags[]" value="11" type="checkbox" /> Melancholic</label>
     <label><input name="tags[]" value="12" type="checkbox" /> Neutral</label>
     <label><input name="tags[]" value="13" type="checkbox" /> Optimistic</label>
     <label><input name="tags[]" value="14" type="checkbox" /> Playful</label>
     <label><input name="tags[]" value="15" type="checkbox" /> Positive</label>
     <label><input name="tags[]" value="16" type="checkbox" /> Quirky</label>
     <label><input name="tags[]" value="17" type="checkbox" /> Relaxed</label>
     <label><input name="tags[]" value="18" type="checkbox" /> Sentimental</label>
     <label><input name="tags[]" value="19" type="checkbox" /> Uplifting</label>
     <label><input name="tags[]" value="20" type="checkbox" /> Warm</label>
    

    Also I don't think Form::select supports multiple, which I need so may post improvement for that.
  • Thank you for this mate, I thought to ask if you have made smth similar with Form::radio() ? Thanks :)
  • Sure, here! http://scrp.at/wt [edit bug fixed version] I also submitted a patch to the repo to allow the Form::select method to accept multiple selected options, for completeness this is here. http://scrp.at/wn Btw in the method I'm not sure what lines 22/23 achieve (as $values isn't used again)
  • Will Kelly wrote on 02/16/11 9:56 am:
    Sure, here! http://scrp.at/wm I also submitted a patch to the repo to allow the Form::select method to accept multiple selected options, for completeness this is here. http://scrp.at/wn Btw in the method I'm not sure what lines 22/23 achieve (as $values isn't used again)

    Thanks logic box :) But I see some major problem here:
    http://d.pr/8nzx I tried changing $selected to 'selected' but can't refill the posted value... Here is my code:
    <?php
        $array = array(
            'available' => 'Avaialble',
            'retired' => 'Retired',
        );
        echo Form::radios('my_status', $_POST, $array); ?>
    

    I could be doing smth wrong..?
  • It should be $checked not $selected, sorry. Copy paste error, updated method: http://scrp.at/wt The $value param would only be passed as a string as you wouldn't be able to check more than one item.
    <?php
    
    $array = array(
        'available' => 'Avaialble',
        'retired' => 'Retired',
    );
    
    echo Form::radios('my_status', $_POST['my_status'], $array);
    
    //$_POST['my_status'] = 'available'; (or 'retired')
    
    ?>
    

    Hope that helps!
  • Thank you once again Logicbox :) I've been trying your suggestions but haven't tried: $_POST (was using $_POST instead) thanks once again for pointing out :) It's a needed thing to have those radios :)

Howdy, Stranger!

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

In this Discussion