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

  • SEARCH
  • Home
  • 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 7594545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:26:37+00:00 2026-05-30T21:26:37+00:00

I am trying to use form validation for my form after user submits it.

  • 0

I am trying to use form validation for my form after user submits it. My view page has a variable that was passed by my controller. The view page works fine until I submit the form to validate. It gave me errors saying the variables passed by controller were undefined. I am not sure how to solve this. Any thoughts?

// Controller - status.php
public function load_view ()
{
    $this->load->model('project_query');
    $JNresults=$this->project_query->get_jobnumber();
    $data['JNresults']=$JNresults->result(); //pass to view
    $data['view']='form_view';
    $this->load->view('include/template',$data);
}

public function validate ()
{
    //validate form

    $data['error']='There are errors in your form.';
    $data['view']='form_view';
    $this->load->view('include/template',$data);
}
// View page - form_view.php
foreach ($JNresults as $row):    //work fine when first loaded. 
    echo $row->job_number;
endforeach;

echo form_open('status/validate');
echo validation_errors();
// input fields...
echo form_submit($submit);
echo form_close();

I get undefined variable $JNresults after I submit the form. I understand the view page don’t recognize it because it was passed from the controller. I just want to know if anyone can help me to solve this.

  • 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-30T21:26:38+00:00Added an answer on May 30, 2026 at 9:26 pm

    In your validate() method, you aren’t using $data['JNresults']=$JNresults->result(); so the variable $JNresults never gets populated in your view.

    The solution:

    Validate the form in load_view(), and get rid the of validate() method:

    public function load_view()
    {
        // set validation rules
        if ($this->form_validation->run())
        {
            // do something
        }
    
        $this->load->model('project_query');
        $JNresults=$this->project_query->get_jobnumber();
        $data['JNresults']=$JNresults->result(); //pass to view
        $data['view']='form_view';
        $this->load->view('include/template', $data);
    }
    

    Then change form_open('status/validate') to form_open() or form_open('status/load_view').

    It looks like you aren’t using the $data['error'], which is fine because you don’t need it. validation_error() returns an empty string if there are no errors, so if you want to add an extra message you can just check if it’s empty:

    if ($errors = validation_errors())
    {
        echo 'There were errors:';
        echo $errors;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use form validation that is working in this example with my
I'm trying to use MVC2 client-side validation in a partial view that is rendered
I'm trying to create a C# form app that will allow me to use
I'm trying to use jquery to enable a form button only after a radio
I'm creating a JSF 2-application and I'm trying to use form validation in the
I am using this jQuery form validation plugin: http://docs.jquery.com/Plugins/Validation/Methods I am trying to use
I am trying to use jQuery to setup a form validation, but theres this
I'm trying to use jQuery validation plugin to validate a few form fields by
I'm trying to use the Jquery validation plugin to validate my form. I have
All, I'm trying to use the jQuery Form Validator (http://docs.jquery.com/Plugins/Validation). However I'd like to

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.