![]() |
Hidden field not been submitted with form validation - 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: Hidden field not been submitted with form validation (/showthread.php?tid=63958) |
Hidden field not been submitted with form validation - wolfgang1983 - 12-27-2015 I have a small issue. I am now using form helper and form validation to submit my up and down votes. But for some reason using the form validation on the down_vote does not submit it keeps on returning false. I am not sure why form validation does not work with hidden fields. The var dump is working. form helper is auto loaded. Code: array (size=1) Controller Forum PHP Code: <?php PHP Code: <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 text-center"> RE: Hidden field not been submitted with form validation - Diederik - 12-28-2015 You could try the following to debug your problem: PHP Code: <?php RE: Hidden field not been submitted with form validation - andresweb - 12-28-2015 The third parameter test <?php echo form_hidden('down_vote', '1','id="down_vote"');?> RE: Hidden field not been submitted with form validation - wolfgang1983 - 12-28-2015 (12-28-2015, 12:04 AM)Diederik Wrote: You could try the following to debug your problem: Thank you for tip in the set_rules for some reason to make it work requires a third part i.e required and then it worked. Unsure why need that third part to make it work? Code: $this->form_validation->set_rules('down_vote', 'Down Vote', 'trim|required'); Will not work if just have Code: $this->form_validation->set_rules('down_vote', 'Down Vote'); RE: Hidden field not been submitted with form validation - Diederik - 12-28-2015 Ah yes, sorry I didn't spot that error in my first response. You need to tell the validation library which rules needs to be applied for each POST variable. You should always make your validation rules as strict as possible. In your case you expect a value of 1 and nothing else. Code: $this->form_validation->set_rules('down_vote', 'Down Vote', 'trim|required|integer'); This way the form is only validated when a integer is posted and not some SQL injection hacker string for example. Not that it matters in your particular codeset because you don't use the posted value itself but it's good practice to make sure all the posted fields contain data of a type that you expect it should be before you can (safely) use that data. Here is a list with all the build in validation rules: https://www.codeigniter.com/userguide3/libraries/form_validation.html#rule-reference But you can also write your own validation rules to meet your needs. RE: Hidden field not been submitted with form validation - wolfgang1983 - 12-28-2015 (12-28-2015, 12:50 AM)Diederik Wrote: Ah yes, sorry I didn't spot that error in my first response. You need to tell the validation library which rules needs to be applied for each POST variable. You should always make your validation rules as strict as possible. In your case you expect a value of 1 and nothing else. That is really good to know thanks. I am having a go at making my own forum even though there are some all ready out there just good practice. With bootstrap etc and moderator & user groups etc |