1

I m coding a Tab based form using bootstrap and codeigniter.I have so many input fields and files that need to be uploaded.

And , also i have server side validation that when validation fails i show error messages but , the user is again required to fill all that long data again and i dont want that to happen.

So, how can i repopulate the data again after a post and validation occur.

Thankyou so much , this a pain in da ass.

1

1 Answer 1

3

Yes you can follow the link mentioned in the comments above and can set values using set_value(); e.g. -

<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />

However I had noticed that it would set values for the fields which were being validated only so I had copied and customised the set_value to my own helper function e.g.

function set_value_myappname($field = '', $default = '', $fieldtype='text') {

    if($fieldtype == 'text') {
        if ( ! isset($_POST[$field]))
        {
            return $default;
        }
        return form_prep($_POST[$field], $field);
    }   
}

please note I did that with an older version of CI. The current 3.0 might have already something else in place for this sort of behaviour.

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.