$_POST data not mapping to $this->input->post |
[eluser]randalrust[/eluser]
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: $this->input->post['fname']=$_POST['fname']; $fname=$this->input->post['fname']; 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
[eluser]randalrust[/eluser]
Here is the code that I am working with. CONTROLLER ---------- <?php class Form extends Controller { function index(){ //echo 'Hello World'; //$this->load->helper(array('form','url')); #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); #validations $this->load->library('validation'); $rules['fname']='required'; $rules['email']='required|valid_email'; $this->validation->set_rules($rules); #load view if($this->validation->run()==FALSE){ $this->load->view('form_view', $data); } else { #get post data $this->input->post['fname']=$_POST['fname']; $fname=$this->input->post['fname']; echo $fname; $email=$this->input->post['email']; $comments=$this->input->post['comments']; $seminars=''; foreach($this->input->post('seminar') as $value){ $seminars.="$value\n"; } $message=$fname." would like to register for the following seminars:\n"; $message.=$seminars; /* #set email fields $this->email->from($email, $fname); $this->email->to('[email protected]'); $this->email->subject('seminar registration'); $this->email->message($message); $this->email->send(); */ #load the view file $this->load->view('formsuccess'); } } } ?> VIEW ----------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Untitled</title> <meta http-equiv="content-type" content="text/xhtml; charset=iso-8859-1" /> </head> <body> <h1>registration form</h1> <p>please complete the following form</p> <?php echo $this->validation->error_string; echo form_open('/form/index'); ?> <h3>personal information</h3> <fieldset> <div class="row"> <span class="label"><label for="fname">first name »</label></span> <?php echo form_input($fname); ?> </div> <div class="row"> <span class="label"><label for="email">email »</label></span> <?php echo form_input($email); ?> </div> </fieldset> <h3>seminar</h3> <p>please select the seminars that you would like to attend:</p> <fieldset> <label for="purpose">purpose</label><?php echo form_checkbox($purpose); ?> <label for="prepare">prepare</label><?php echo form_checkbox($prepare); ?> <label for="principles">principles</label><?php echo form_checkbox($principles); ?> <label for="power">power</label><?php echo form_checkbox($power); ?> </fieldset> <h3><label for="comments">comments</label></h3> <fieldset> <div class="row"> <?php echo form_textarea($comments); ?> </div> </fieldset> <fieldset> <?php echo form_submit('submit', 'Submit'); ?> </fieldset> <?php echo form_close(); ?> </body> </html>
[eluser]tonanbarbarian[/eluser]
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 i.e. Code: $fname = $this->input->post('fname'); Code: $fname = $this->input->post['fname'];
[eluser]xwero[/eluser]
[quote author="randalrust" date="1199901553"] $this->input->post['fname']=$_POST['fname']; $fname=$this->input->post['fname']; [/quote] I don't know it it's a typo but method arguments are surrounded by rounded brackets Code: $this->input->post('fname')
[eluser]randalrust[/eluser]
[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. Thanks!
[eluser]Derek Allard[/eluser]
Since this is resolved, allow me to share my favourite. Code: $this->db>get('something'); I probably do that 4 times daily...
[eluser]johnwbaxter[/eluser]
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]johnwbaxter[/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? |
Welcome Guest, Not a member yet? Register Sign In |