![]() |
Form validation: Manipulated form fields - 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: Form validation: Manipulated form fields (/showthread.php?tid=52033) |
Form validation: Manipulated form fields - El Forum - 05-27-2012 [eluser]cmh24[/eluser] Hi everybody, let's say I have a select form field like this Code: <select name="type" id="type" size="1"> Now somebody changes the value of one of the options, selects this option and submits the form. How can I check that he only submitted the prefined values. My current solution is to use numbers instead of male and female and use the greater_than and less_than rules from the form validation class. But then I have to transform the numbers to the actual strings. So this is not ideal. What would you suggest! Many greetings! Max Form validation: Manipulated form fields - El Forum - 05-27-2012 [eluser]Aken[/eluser] Create an array of options in your controller. Then use it to both A) pass to the view to display those options, and B) check the submitted value if it exists in the array. Form validation: Manipulated form fields - El Forum - 05-27-2012 [eluser]cmh24[/eluser] I found a solution. Inside the form validation library I found the regex_match method, which is not documented in the userguide. So to check for values 1,2,3 I just use regex_match[/[123]/]. It works. But now I still do not know how to check for full strings. For example female and male (see my first post). I used something like regex_match[/["male", "female"]/], which did not work. edit: Now, I just changed the type of brackets, and at least it is partly working. I used: regex_match[/(male)/] But for some reason this does not work: regex_match[/(male|female)/] Maybe someone can help. |