[SOLVED] $_POST is getting only the last field - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: [SOLVED] $_POST is getting only the last field (/showthread.php?tid=1462) |
[SOLVED] $_POST is getting only the last field - fcordeiro - 03-11-2015 I'm starting now with Codeiginiter and for days I'm trying to fix this code. I have a lot of fields in my form: name, email, phone, message, etc, but $_POST only get the last field, Message. View HOME.PHP PHP Code: <?php echo form_open('/home/cadastrar'); ?> Controller HOME.PHP PHP Code: public function cadastrar() { So, form_validation always return FALSE because I'm only receiving data from the textarea "message". Form submited: Data received ($_POST): Thank you for your help. RE: $_POST is getting only the last field - ciadmin - 03-11-2015 Did you notice that your 'message' field is the only one with a 'name' attribute? PHP uses that for POST parameters, and not the 'id' attribute. Add the 'name' attribute to your other fields and they should be accessible to your code. RE: $_POST is getting only the last field - fcordeiro - 03-11-2015 (03-11-2015, 07:46 PM)ciadmin Wrote: Did you notice that your 'message' field is the only one with a 'name' attribute? Thank you! Just after post the message I saw it. CTRL + C / CTRL + V, always replicating our own mistakes This post can be closed. RE: [SOLVED] $_POST is getting only the last field - ciadmin - 03-11-2015 (03-11-2015, 08:06 PM)fcordeiro Wrote:(03-11-2015, 07:46 PM)ciadmin Wrote: Did you notice that your 'message' field is the only one with a 'name' attribute? I will leave the post here, in case other users have the same problem. It is not the first time I have seen it RE: [SOLVED] $_POST is getting only the last field - mwhitney - 03-12-2015 (03-11-2015, 07:46 PM)ciadmin Wrote: Did you notice that your 'message' field is the only one with a 'name' attribute? I just wanted to add a note that this is part of the standard for HTML forms, so it happens in the browser before PHP gets involved. I think most of us, as web developers, run into this at some point (hopefully early) in our careers, regardless of what language we use on the server. With the increased use of AJAX libraries to submit forms, I occasionally run into a library that builds a POST and uses ID values if the names aren't present, but I would generally recommend avoiding depending on behavior like that, as it just becomes confusing and/or difficult to troubleshoot down the road. RE: [SOLVED] $_POST is getting only the last field - emailtech35 - 01-14-2020 Great post! This blog helps roadrunner users for Roadrunner email not working error. This post gives solutions for this error. Thanks for sharing this great post. |