Welcome Guest, Not a member yet? Register   Sign In
$_POST data not mapping to $this->input->post

I am completely new to actually coding with CI and MVC, but have a lot of experience with OOP in PHP. I am working through a tutorial [1][2], but I'm having an issue that I don't quite understand.

My form_view has the following fields:

first name
last name
seminar (four checkboxes)
comments (textarea)

When I properly fill out and submit the form and the data is passed to the controller, I keep getting error messages that say:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: email

The exception is the 'seminar' field. If I check a box, then it works properly.

I know the data is getting passed, because I can echo the $_POST array and see it.

Oddly enough, I added this to my controller file:


Then I was able to avoid the error on the 'first name' field. So what it looks like is that the $_POST array is not getting properly passed to $this->input->post. Any thoughts?

[1] http://godbit.com/article/introduction-to-code-igniter
[2] http://godbit.com/article/introduction-t...ter-part-2

Here is the code that I am working with.


class Form extends Controller {

function index(){
//echo 'Hello World';
#Input and textarea field attributes
$data['fname'] = array('name' => 'fname', 'id' => 'fname');
$data['email'] = array('name' => 'email', 'id' => 'email');
$data['comments'] = array('name' => 'comments', 'id' => 'comments', 'rows' => 3, 'cols' => 40);

#Checkbox attributes
$data['purpose'] = array('name' => 'seminar[]', 'id' => 'purpose', 'value' => 'Purpose of Prayer', 'checked' => FALSE);
$data['prepare'] = array('name' => 'seminar[]', 'id' => 'prepare', 'value' => 'Prepare for Prayer', 'checked' => FALSE);
$data['principles'] = array('name' => 'seminar[]', 'id' => 'principles', 'value' => 'Principles of Prayer', 'checked' => FALSE);
$data['power'] = array('name' => 'seminar[]', 'id' => 'power', 'value' => 'Power in Prayer', 'checked' => FALSE);

#Load our view
$this->load->view('form_view', $data);
#load view
$this->load->view('form_view', $data);
else {
#get post data
echo $fname;
foreach($this->input->post('seminar') as $value){
$message=$fname." would like to register for the following seminars:\n";
#set email fields
$this->email->from($email, $fname);
$this->email->to('[email protected]');
$this->email->subject('seminar registration');
#load the view file



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;meta http-equiv="content-type" content="text/xhtml; charset=iso-8859-1" /&gt;

<h1>registration form</h1>
<p>please complete the following form</p>
echo $this->validation->error_string;
echo form_open('/form/index');
<h3>personal information</h3>
<div class="row">
<span class="label"><label for="fname">first name &raquo;</label></span>
&lt;?php echo form_input($fname); ?&gt;
<div class="row">
<span class="label"><label for="email">email &raquo;</label></span>
&lt;?php echo form_input($email); ?&gt;
<p>please select the seminars that you would like to attend:</p>
<label for="purpose">purpose</label>&lt;?php echo form_checkbox($purpose); ?&gt;
<label for="prepare">prepare</label>&lt;?php echo form_checkbox($prepare); ?&gt;
<label for="principles">principles</label>&lt;?php echo form_checkbox($principles); ?&gt;
<label for="power">power</label>&lt;?php echo form_checkbox($power); ?&gt;
<h3><label for="comments">comments</label></h3>
<div class="row">
&lt;?php echo form_textarea($comments); ?&gt;
&lt;?php echo form_submit('submit', 'Submit'); ?&gt;
&lt;?php echo form_close(); ?&gt;


please post a complete example of the problematic code and indicate where the error is.
be sure that you are using the post correctly.
it should be post as a method not an array
$fname = $this->input->post('fname');
$fname = $this->input->post['fname'];

[quote author="randalrust" date="1199901553"]

I don't know it it's a typo but method arguments are surrounded by rounded brackets

[quote author="xwero" date="1199901996"]I don't know it it's a typo but method arguments are surrounded by rounded brackets[/quote]

That was it. Can't believe I missed it, but I'm pretty used to brackets because I use the adodb abstraction library.


I do that more often than you can imagine!

[eluser]Derek Allard[/eluser]
Since this is resolved, allow me to share my favourite.

I probably do that 4 times daily...

See Derek, this is why we all need a CI IDE to help us with the stupid things that we do.

Can you quickly make one and post it on this thread please. I'll give you about 10 minutes...

[eluser]Derek Allard[/eluser]

That's cheating!

Still you managed it in under 10 mins so i suppose i shouldn't complain!

I use coda, has there been anything similar done for that do you know?

Theme © iAndrew 2016 - Forum software by © MyBB