Welcome Guest, Not a member yet? Register   Sign In
input->post not working

I am new to CI, and seem to having a strange issue. I can use the $_POST var to get values from forms. As soon as I try to use input->post('var'), I get nothing to returned to the controller.
Here is the code

function customer_insert()
        $first_name = $this->input->post('first_name');
        $last_name = $this->input->post('last_name');
        $email = $this->input->post('email');
        $phone = $this->input->post('phone');
        $address = $this->input->post('address');
        $city = $this->input->post('city');
        $state = $this->input->post('state');
        $zip = $this->input->post('zip');
        $account = $this->input->post('account');
        $data = array(
        'first_name' => '$first_name',
        'last_name'  => '$last_name',
        'email' => '$email',
        'phone' => '$phone',
        'address' => '$address',
        'city' => '$city',
        'state' => '$state',
        'zip' => '$zip',
        'account' => '$account',    
class Account_model extends Model
     function __construct()
    function get_all_accounts($word)
    echo "Database". ' ' .$word;    
    $myData = $this->db->get($word);
    return $myData->result();
    function insert_customer($data)

<div id="form">
            <legend>Customer Account Details</legend>
            &lt;?= form_open('customers/customer_insert');?&gt;
            &lt;?=form_label("First Name:(Required)","first_name");?&gt;
            &lt;?=form_label('Last Name:(Required)','Last_name');?&gt;
            <legend>Customer Address Details</legend>
            &lt;?= form_input('state','');?&gt;
            &lt;?=form_label('Zip Code:(Required)','zip');?&gt;
            &lt;input type="hidden" name="account" value="&lt;?= rand(1000,50000); ?&gt;"&gt;
            &lt;?=form_submit('','Submit Data');?&gt;

I can't see where you've opened your form... Am I missing something?

EDIT: I take that back. I saw the fieldset first and assumed you didn't open the form, as fieldsets should be inside the form.

EDIT2: OK, I think this has something to do with your nesting. You open a fieldset, then the form, but then you close the fieldset before the form. Switching the form_open, and form_fieldset should fix it?

Thanks for reply. I fixed the nesting problem and the issue still only sends $first_name,$last_name etc. I tried a form with no nesting and still getting just empty vars like this $email.

My suggestion would be to validate your page. Once you are sure it's valid HTML, it's a lot easier to troubleshoot. Smile

I fixed the problem. I was putting '' quotes around the my post vars which turned them into strings. I feel real dumb. lol
Thanks for the help

Oh I see. I can't believe I didn't spot that. Well done for solving it. I'll bet you won't do that again in a hurry.

lol, that was the problem I was in hurry trying to do a simple thing.
wasted 4 hours yesterday ouch
. :blank:

Just a suggestion for tidier code, put the post vars straight in your $data array.

$data = array();

$data['first_name'] = $this->input->post('first_name');
$data['last_name'] = $this->input->post('last_name');
$data['email'] = $this->input->post('email');
$data['phone'] = $this->input->post('phone');
$data['address'] = $this->input->post('address');
$data['city'] = $this->input->post('city');
$data['state'] = $this->input->post('state');
$data['zip'] = $this->input->post('zip');
$data['account'] = $this->input->post('account');


Yes good point
thanks Smile

Theme © iAndrew 2016 - Forum software by © MyBB