Re: Simpler way to validate form fields? [message #179800 is a reply to message #179799] |
Thu, 06 December 2012 13:55 |
Gilles Ganault
Messages: 27 Registered: September 2010
Karma:
|
Junior Member |
|
|
On Thu, 06 Dec 2012 14:43:57 +0100, Gilles <nospam(at)nospam(dot)com> wrote:
> function getDateFromForm($key, $l=8, $val=null) {
> //Check for date DD/MM/YYYY
> return (isset($_POST[$key])) ?
> filter_var(substr($_POST[$key],0,$l),
>
> FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>"/^\d{2}\/\d{2}\/\d{4}/ "))
> )
> : $val;
> }
I made a mistake, but even after turning $_POST into $_GET, it still
displays nothing:
function getDateFromForm($key, $l=8, $val=null) {
//Check for date DD/MM/YYYY
return (isset($_GET[$key])) ?
filter_var(substr($_GET[$key],0,$l),
FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>"/^\d{2}\/\d{2}\/\d{4}/ "))
)
: $val;
}
//http://192.168.0.1/test.php?mydate=01/02/2012
print getDateFromForm("mydate");
|
|
|