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 6744135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:02:51+00:00 2026-05-26T12:02:51+00:00

I have 2 methods inside my controller, one is responsible for generating the signup

  • 0

I have 2 methods inside my controller, one is responsible for generating the signup page and another is responsible for handing the signup form submission.

<?php

class Signup_c extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
        $data['title'] = 'Sign Up';

        $data['months'] = array(
            '1' => 'January',
            '2' => 'February',
            '3' => 'March',
            '4' => 'April',
            '5' => 'May',
            '6' => 'June',
            '7' => 'July',
            '8' => 'August',
            '9' => 'September',
            '10' => 'October',
            '11' => 'November',
            '12' => 'December'
        );      

        $this->load->view('signup_v', $data);
    }

    function submit() {

            // validation rules here...

        // validate
        if ($this->form_validation->run() === FALSE) {
            $this->load->view('www/signup_v');
        }
        else {
                    // add info to database here...

            $this->load->view('www/signup_success_v');
        }

    }

}

Now the problem is this, if there is a validation error then the user is returned back to the signup page and the validation errors are displayed. However no title or date is shown because those variables were defined inside the index() method and not the submit() method.

What is the best solution to this, I don’t want to repeat my self and copy over those 2 variable declarations inside the signup method too. Is there a way to make it work in both method’s views?

  • 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-26T12:02:51+00:00Added an answer on May 26, 2026 at 12:02 pm

    Why not assign class variables? before construct:

    $title = 'Whatever';
    $months = array('january', 'february');
    

    then inside your methods access them with $this->title and $this->months

    Additionally, why not just post back to your index method and have it do post processing before anything else? so your index method begins with something like this:

    if(!empty($_POST))
    {
        // do some kind of validation here
        // or call a private method in this class and set your class vars accordingly
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few methods inside my view controller that load up for future
I have a method that I'm writing that is calling another overloaded method inside
I have methods with more than one parameter that are guarded against bad input
I have an nsarray that when I NSLog it from one of my methods
I have written an ASP.NET MVC application that runs inside an IFrame. When one
I am running JSF 2.0 I currently have one java controller that is called
So I have an application that embeds a Navigation Controller inside a Tab Bar
In my controller I have two actions called Friends. The one that executes depends
I have placed all my admin controllers inside an Admin folder in Controller folder.
I have a method that varies by a single method call inside, and I'd

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.