Welcome Guest, Not a member yet? Register   Sign In
Form validation: Manipulated form fields
#1

[eluser]cmh24[/eluser]
Hi everybody,

let's say I have a select form field like this

Code:
<select name="type" id="type" size="1">
    <option value="male" &lt;?php echo set_select('type', 'male', TRUE); ?&gt; >Male</option>
    <option value="female" &lt;?php echo set_select('type', 'female'); ?&gt; >Female</option>
  </select>

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
#2

[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.
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB