Help Submit Button in codeigniter forms. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Help Submit Button in codeigniter forms. (/showthread.php?tid=16965) |
Help Submit Button in codeigniter forms. - El Forum - 03-21-2009 [eluser]Unknown[/eluser] Hey everyone, I'm having an issue I hope you can help me with.. I am just starting with codeigniter and have been diligently following the blog screencast, step by step, however when submitting the comment form y run into the following problem: It seems by submitting the form the submit button is also being passed on as a field to the database causing the following error message to display: A Database Error Occurred Error Number: 1054 Unknown column 'submit' in 'field list' INSERT INTO `comments` (`entry_id`, `body`, `author`, `submit`) VALUES ('2', 'dfgdg', 'fdsf', '') I finally got it to work by creating a field called submit on the DB, but obviously this is not normal. Am I making a NOOB mistake, I have gone through all the code and have been able to figure it out. Anybody have any insight, btw I apologize in advance if this is a dumb question, but your help is throughly appreciated. Below my code. View Code: <?=form_open('blog/comment_insert');?> Code: function comment_insert() A Database Error Occurred Error Number: 1054 Unknown column 'submit' in 'field list' INSERT INTO `comments` (`entry_id`, `body`, `author`, `submit`) VALUES ('2', 'dfgdg', 'fdsf', '') [/b] Help Submit Button in codeigniter forms. - El Forum - 03-21-2009 [eluser]Dunrobin[/eluser] I think it's because of your code here: Code: <?php echo form_submit('submit')?> I believe it should be: Code: <?php echo form_submit('submit', 'Submit')?> You left out the 2nd parameter. UPDATE: Forget that. If the form submitted the 2nd parameter probably doesn't matter. I looked at your insert code again and realized that you are passing the $_POST array, which would include the name of the submit button. You should probably make a $data array from the $_POST values first and pass that along in your insert. Help Submit Button in codeigniter forms. - El Forum - 03-22-2009 [eluser]therealmaloy[/eluser] i would suggest that you use the associative array method... for sure you know this but i guess it's one of the neat methods out there... Code: // validation here for security and data integrity reasons Help Submit Button in codeigniter forms. - El Forum - 03-22-2009 [eluser]Clooner[/eluser] The easiest way is to copy the $_POST array and leave out the submit key. Something like this. Code: $new_array=array(); Help Submit Button in codeigniter forms. - El Forum - 02-20-2012 [eluser]himalking[/eluser] Although this might be too late in case someone else interested you can do either: 1- remove the "name" attribute from the input tag //hence won't be included in the $_POST array. 2- or use unset($_POST['Submit']) //this will remove the submit entry form the $_POST array. then use your insert normally. however it is not recommended to insert the data using $_POST directly without filtering for security. Help Submit Button in codeigniter forms. - El Forum - 02-21-2012 [eluser]Rolly1971[/eluser] use: $data = $this->input->post(); unset($data['submit']); another alternative would be to not use the ci form libarary for the submit button, and go this route: <button type="submit">Submit</button> |