Welcome Guest, Not a member yet? Register   Sign In
Form Validation
#9

(This post was last modified: 08-05-2015, 07:20 AM by CroNiX.)

If you want to repopulate the form, you shouldn't redirect. PHP's $_POST superglobal vars only exists for one request. If you redirect you lose the contents of $_POST.

My controllers usually look something like this:

PHP Code:
// Was form submitted?
if ($this->input->server('REQUEST_METHOD') == 'POST')
{
  
// validate form fields here using validation library.
  // If success, redirect to success page
}

//If we made it this far in the code, either the form was submitted and failed validation, OR the person just came to the page for the first time. In either case, just display the form. The view will handle showing field errors using the validation library if any exist.
$this->load->view('your_form_view'); 
Reply


Messages In This Thread
Form Validation - by ignitedcms - 08-04-2015, 11:11 AM
RE: Form Validation - by mwhitney - 08-04-2015, 01:36 PM
RE: Form Validation - by Diederik - 08-04-2015, 03:02 PM
RE: Form Validation - by ignitedcms - 08-04-2015, 03:40 PM
RE: Form Validation - by Diederik - 08-04-2015, 10:36 PM
RE: Form Validation - by ignitedcms - 08-05-2015, 12:08 AM
RE: Form Validation - by mwhitney - 08-05-2015, 07:26 AM
RE: Form Validation - by Diederik - 08-05-2015, 01:43 AM
RE: Form Validation - by Wouter60 - 08-05-2015, 06:50 AM
RE: Form Validation - by CroNiX - 08-05-2015, 07:20 AM
RE: Form Validation - by ignitedcms - 08-05-2015, 11:55 AM
RE: Form Validation - by mariek - 08-14-2015, 08:40 AM
RE: Form Validation - by mwhitney - 08-14-2015, 09:54 AM
RE: Form Validation - by mariek - 08-17-2015, 12:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB