Search code examples
phpcodeigniterpostmodel-view-controllerform-fields

Form field with id attribute is not being submitted with HTML form


I have two forms and two controllers.

I want to input data into the first controllers view. On that page submit the data to the second controller and display it on that controllers view.

Now I have tried to insert the form input data in an array in my controller and then access it as a normal variable in the view but without luck.

My Controller for first form

function new_order_details() 
{
    $this->load->view('sales/new_order_details');
}

My input form view: new_order_details'

<form id="sales_order_details" action="/sales/new_blank_order_lines" method="post">
    <input type="text" id="customer" />
    <input type="submit" name="blank_order" id="blank_order" value="Continue">
</form>

My Controller for second form

function new_blank_order_lines() 
{
    $data = array(
        'customer' =>$this->input->post('customer')
    );
    $this->load->view('sales/new_blank_order_lines',$data);
}

and my view where I want to display data

<?php echo "--" . $customer . "--"; ?>

The output of the above is that the variable $customer is empty.


Solution

  • It is empty because you have not given name parameter to customer input field in view file.

    Write html as below

    <input type="text" id="customer" name="customer" />