Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4086042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:40:11+00:00 2026-05-20T18:40:11+00:00

Is it possible to display errors and repopulate fields on a form that is

  • 0

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 ExpressionEngine, 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:40:12+00:00Added an answer on May 20, 2026 at 6:40 pm

    Great question, and one which took me a long time to figure out the best way to solve.

    The CodeIgniter Form Validation library is great, but can only be used with proper views and controllers, so it doesn’t work out of the box when you are developing a front end tag.

    Normally, the preferred way of submitting a front-end form is to register an ‘Action’ in your upd.addon.php file (I’m guessing you have done this for your submit_form() function). This is then assigned a number, which you can post with the url /index.php?ACT=37 or something similar. This is a good system, because it means we know the form submission came from our module. However, with input forms, this is a hindrance, because it means we can’t repopulate input fields. You therefore need to configure the input form to post back to the current URL, and wait until the template engine tries to render your tag before handling the form submission.

    The easiest, and visually ugliest way to achieve this, is to use $this->EE->output->show_user_error(FALSE, array_of_errors). You can actually use this from either an action, or within your module code. It displays the standard grey EE message page we have all grown to know and hate.

    With that sort of intro, you probably knew the solution wasn’t going to be quite that simple, right? Here’s a skeleton of a tag function which implements inline error checking:

    function my_form()
    {
        // load default tag variables
        $tag_vars = array();
        $tag_vars[0] = array(
            'first_name' => '',
            'error:first_name' => '',
            'last_name' => '',
            'error:last_name' => ''
        );
    
        // handle a form submission
        if ($this->EE->input->post('my_form_hidden') == '1'))
        {
            // load POST data into tag
            $tag_vars[0]['first_name'] = $this->EE->input->post('first_name', TRUE);
            $tag_vars[0]['last_name'] = $this->EE->input->post('last_name', TRUE);
    
            // use CI validation library to check submission
            $this->EE->load->helper('form');
            $this->EE->load->library('form_validation');
            $this->EE->form_validation->set_rules('first_name', 'lang:first_name', 'required');
            $this->EE->form_validation->set_rules('last_name', 'lang:first_name', 'required');
    
            $valid_form = $this->EE->form_validation->run();
            if ($valid_form)
            {
                // probably save something to database, then redirect
            }
            else
            {
                $form_errors = array();
                foreach (array('first_name', 'last_name') as $field_name)
                {
                    $field_error = form_error($field_name);
                    if ($field_error)
                    {
                        $form_errors[] = $field_error;
                        $tag_vars[0]['error:'.$field_name] = $field_error;
                    }
                }
    
                if ($this->EE->TMPL->fetch_param('error_handling') != 'inline')
                {
                    // show default EE error page
                    return $this->EE->output->show_user_error(FALSE, $form_errors);
                }
            }
        }
    
        // parse and output tagdata
        $out = $this->EE->functions->form_declaration(array(
            'action' => $this->EE->functions->fetch_current_uri(),
            'hidden_fields' => array('my_form_hidden')));
        $out .= $this->EE->TMPL->parse_variables($tagdata, $tag_vars);
        return $out.'</form>';
    }
    

    This way, the designer can specify error_handling="inline" in the tag if they want inline errors, otherwise they will just be redirected to the standard error form. If they do request inline error handling, they will simply need to make sure their inputs look like this:

    <input type="text" name="first_name" value="{first_name}" />
    {error:first_name}
    

    Note the hidden field we submit along with the form, this allows us to ensure we only handle submission of this form, and not any other forms on the page, such as a login form or something. If you have more than one instance of your form on a page (say inside a channel entries loop or something), you will need to implement some trickery to make sure that you only handle the form instance which was submitted, for example by submitting along entry_id as a hidden field too.

    Glad to get that all documented, hopefully this will be useful to other EE developers too!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to animate the change of a UIProgressView such that the display
Is it possible to have two ValidationSummary controls. One to display popup errors for
is it possible to display ⇓ entity in ie6? It is being display in
With the DataGridView it is possible to display cells containing some long text. The
Is it possible to have multiple view of the same display object? (e.g. same-computer
Possible Duplicate: 500 - An error has occurred! DB function reports no errors when
I find the standard Powershell display of errors (red text, multi-line display) a bit
My main issue is that I want to display an custom error page when
On PRO ASP.NET MVC book: It is certainly possible to put domain logic into
In JSF is it possible to have a datatable displays records as follows? [Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.