Created
September 25, 2012 16:52
-
-
Save drakakisgeo/3783103 to your computer and use it in GitHub Desktop.
Laravel:Grab any input that starts with a $string and create validation rules array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_jsfields($input,$begins_with,$numpos,$validation_string){ | |
$jsfields = array(); | |
$getkeys = array_keys($input); | |
for($i=0;$i<sizeof($getkeys);$i++){ | |
if(preg_match("/$begins_with/i", trim($getkeys[$i]))){ | |
$jsfields[$begins_with.$getkeys[$i][$numpos-1]] = ''.$validation_string.''; | |
} | |
} | |
return $jsfields; | |
} | |
///// After this only thing you have to do is merge this returned array with your $rules array. | |
//// Usage example: $rules = array_merge($rules, get_jsfields($input,"date_",6,"required|date")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment