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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:31:05+00:00 2026-06-12T06:31:05+00:00

Using codeigniter 2.1.2, I have a form view loaded through a controller that takes

  • 0

Using codeigniter 2.1.2, I have a form view loaded through a controller that takes a parameter. This parameter is a boolean that tells the view whether to render certain content on the form.

the URI of the standard form is: ordering/create/
but if the form should be rendering as a ‘holiday’ form is: ordering/create/holiday

If the submitted form does not pass validation, the standard form is always shown. How do I get the last segment to persist through validation and form re-population?

Here is my controller function.

public function create($holiday = NULL)
{
    $data['holiday'] = ($holiday != NULL) ? TRUE : FALSE;

    //load the code igniter helpers we'll be using
    $this->load->helper('form');
    $this->load->library('form_validation');

    //set the page title
    $data['title'] = 'Create an Order';

    //validate the form input
    $this->form_validation->set_rules('firstName','First Name','required');
    $this->form_validation->set_rules('lastName','Last Name','required');
    $this->form_validation->set_rules('phoneNumber','Phone Number','required|callback_validate_phoneNumber');
    $this->form_validation->set_rules('emailAddress','Email Address','required|valid_email');               
    $this->form_validation->set_rules('pickupDate','Pickup Date','required|callback_validate_pickupDate');
    $this->form_validation->set_rules('pickupTime','Pickup Time','required');

    //check that at least one product was selected
    $this->load->model('products_model');
    $data['products'] = $this->products_model->get_online_products($data['holiday']);
    $productSelections = array();
    $totalProducts = 0;
    foreach($data['products']->result() as $product)
    {
        $productSelections[$product->productProductSizeId] = $this->input->post('product_'.$product->productProductSizeId);
        $totalProducts += $productSelections[$product->productProductSizeId];
    }

    $pickupDate = new DateTime($this->input->post('pickupDate'));

    //if the form failed validation, or there is no form data yet, send the user back to the form
    if($this->form_validation->run() === FALSE || $totalProducts == 0)
    {
        $this->load->model('calendar_model');
        $data['calendarRules'] = $this->calendar_model->get_rules($data['holiday']);

        $data['productSelections'] = $productSelections;

        if($this->form_validation->run() === TRUE && $totalProducts == 0)
        {
            $data['productsError'] = 'You must order at least one product';
        }

        $this->load->view('templates/header', $data);
        $this->load->view('ordering/create', $data);
        $this->load->view('templates/footer');
    }
    else
    {
        //save the data to the DB
        $savedData = $this->ordering_model->create_order($data['holiday']);

        //send the confirmation email and redirect to the confirmation page
        $this->send_confirmation($savedData['orderHeader']['orderId']);
    }
}
  • 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-06-12T06:31:06+00:00Added an answer on June 12, 2026 at 6:31 am

    In controller ordering, create a method create($holiday = null).

    Then you do this:

    $data['holiday'] = ($holiday != NULL) ? true : false;
    $this->load->view('yourView', $data);
    

    To persist the value of holiday you should set the form submit action accordingly.

    In your view, you could do something like this:

    <?php
    $submitUrl = site_url('ordering/create');
    if ($holiday) {
        $submitUrl .= '/holiday';
    }
    
    <form method="post" action="<?= $submitUrl ?>">
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form that validates the fields on submit through ajax (using Codeigniter's
I have this function on my controller (Im using CodeIgniter) that reads the database,
I am using codeigniter and Jquery. I have an upload form in my view
I'm using the CodeIgniter PHP framework. I have a simple form that has an
I'm using codeigniter for this project. I have a search form and search form
i'm using Codeigniter. i have a form which takes information about users. What i
I have a codeigniter application.In that i call the controller function using ajax/jquery.But when
I am using Codeigniter framework and I have a form with input fields. When
i am using codeigniter. i have a table to be displayed in a view
I'm building my first CodeIgniter app - and have a registration form. I'm using

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.