I’m building a CRUD system with codeigniter.
The user selects an item, and its details are queried from the db, and populate the form fields.
The user can then decide if they want to update that item, or duplicate it and create a new item.
I wanted the duplication to happen like this:
After clicking the Duplicate button, the value of the item code will be cleared (since the item code is unique, and is user-generated), and the value of the Duplicate button will change to Create a New Item. The user should then type the new item code, and click the Create a New Item button.
The above is easily achieved with Javascript.
Then the form is submitted, and gets validated using CI’s form_validation library.
If the validation fails, I’m reloading the form, displaying the error messages.
Again, that part is easily achieved using CI’s form_validation.
My problem lies here:
After reloading the failed form with the error messages, I want the value of the Duplicate button to remain Create a New Item, and not reset to the initial Duplicate value.
How can I set the value of a button after returning the error messages to the form?
One approach is to send some variable, that acts as flag to determine if the validation is success or it fails.
For example:
// From controller
// In View
Initially set $form_validated = TRUE, when page loads first time.
Hope this helps.
You can even use session to store the data about if form is validated or not