I am in the process of creating an input form on a record specific page e.g. (property/rentals/rec_id). On submission, the data should be inserted, validated and return to the original page from which it was sent with any relevant messages.
- If the validation fails, reload the form page a re-populate the form
Echo the specific validation error - e.g. invalid email address etc
If successful, insert data, reload the page and display success message.
function class() {
$this->load->library('form_validation'); $this->form_validation->set_rules('name','name','required|trim'); $this->form_validation->set_rules('email','email','required|trim|valid_email');
$fields['name'] = 'Name'; $fields['email'] = 'Email Address'; $this->validation->set_fields($fields); if ($this->form_validation->run() == FALSE) { //failed - reload page and re-populate fields with any error messages } else { // display form with success message }
}
Normally this is simply done by 'loading a view' and passing the relevant data to repopulate the page, fields or display messages. But I have to use a 'redirect' back to the product specific page. Is there any good way to do this other than using session data to carry the validation errors..?
Thanks in advance, Michael