in reply to cgi security regex in subroutine
Hopefully, that gives you a decent example of how it might work. Be sure to read the docs, they give lots of examples. Good luck!### Note: untested code # Require food_name and food_group # color is optional, but validate it if they pass it in my $fields_profile = { required => [ "food_name", "food_group" ], optional => [ "color" ], constraints => { food_name => \&validate_word, food_group => \&validate_word, color => \&validate_word, }, # Untaint a field if and only if it passes a constraint untaint_all_constraints => 1, }; # You can simply pass in your CGI object along with your fields pr +ofile my $results = Data::FormValidator->check($q, $fields_profile); # If data is missing or invalid, just print it out if ($results->has_missing or $results->has_invalid) { print "Missing: ", join ", ", $results->missing; print "Invalid: ", join ", ", $results->invalid; } else { print "Excellent food submission!"; } # Called by Data::FormValidator when it needs to validate our para +meters sub validate_word { my $val = shift; return $val =~ /^[\w ]+$/ }
|
|---|