Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Form element value re-population
  • Hi,
    I have a form which contains 2 textboxes and a submit button.
    In controller using form validation, I am making both of the textboxes are required means they must contain a value. If none or one of them are empty and Submit button clicks, it will show error.

    This is as usual just like everyone do.

    But when a user submits a form when only one textbox is filled with any string, it shows error as blah blah field is required.
    But the another textbox which was provided with a value by user vanishes its submitted data.

    So how to re-populate submitted data in value of textbox ?

    In codeigniter, they have inbuilt functions as set_value(), set_select(), set_checkbox()
    For above function, please refer 

    How can I do the same thing in Fuelphp ?

    Thanks
  • After some thoughts, I found a following way to solve it >>
    (In this case, submitted value is populating for textarea)

    <textarea rows="3" name="question" id="elm1"><?php if(Input::post('question') != null) { echo Input::post('question'); } ?></textarea>

    But I think there must be a proper fuelphp core level built function just like set_value(), set_select(), set_checkbox() used in codeigniter.
  • Fuel uses fieldsets to generate forms, which have the entire form handling, including validation, build in. Although there are form helpers, it's not the primary design goal to keep coding forms by hand.

    In your solution, you can reduce it to
    <textarea rows="3" name="question" id="elm1"><?php echo Input::post('question', ''); ?></textarea>
    which isn't any longer or more complex then a set_value() call.

Howdy, Stranger!

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

In this Discussion