Then, I will correct everything to use the ‘role’ and eliminate the preg_match.
Will this do what I am trying to accomplish?
$t_rl = escape_data($_POST['role']); // get the posted role for testing
$a_role = array("admin", "user"); // put allowed roles in the array
if (in_array("$t_rl, $a_tole)) { // test the posted role and if it works set $rl to the correct role
$rl=$t_rl;
} else {
$rl = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid role!</font></p>';
I see the error with the double-quote, and will fix that.
I use a text box because that is about the extent of my knowledge.
I suppose a drop-down selector would be better, but I haven’t tried doing anything like that other than using a program that produces a flash form.
Another way might be to have both options available with a check box, but again, a flash form builder program is the only way I have done that in the past.
I suspect that somewhere in the future, I will have to add a role of editor. That is something I know will be easy once I get the current form working, by adding editor to the array.
You shouldn’t really be using a text field for this, as this is exactly the kind of data the SELECT element was designed for.
Here’s your HTML updated to use a select instead of the text input. You can probably see how easily you can add a new option to the drop down list
Changing this has no effect on your PHP code, the selected value is still sent to PHP as $_POST[‘role’].