We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using form validation class in module to repopulate template form?

Development and Programming

Ted Avery's avatar
Ted Avery
5 posts
15 years ago
Ted Avery's avatar Ted Avery

Is it possible to display errors and repopulate fields on a form that is hard coded into a template? So far I’ve only figured out how to display the errors in a module’s view, but not a template. Based on the logic of EE, I’m guessing I need to somehow make the validation errors visible through a tag in my module, or even generate the whole form from the module, but I’m not sure how to best approach this.

Here is what I have right now.

function submit_form()
    {        
        $this->EE->load->helper('form');
        $this->EE->load->library('form_validation');
        
        $this->EE->form_validation->set_rules('first_name', 'First Name', 'required');
        $this->EE->form_validation->set_rules('last_name', 'Last Name', 'required');
        $this->EE->form_validation->set_rules('address', 'Address', 'required');
        $this->EE->form_validation->set_rules('city', 'City', 'required');
        $this->EE->form_validation->set_rules('province', 'Province', 'required');
        
        if ($this->EE->form_validation->run() == FALSE)
        {
            return $this->EE->load->view('form_errors');
        }
        else
        {
            // success
        }
    }

And for testing, the view simply contains:

echo validation_errors();

Can anyone help?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.