I have a validation check on my site like this
'username' => array('required' => true,'min' => 2,'max' => 50,'unique' => 'users'),
so the username needs to be required, minimum of 2 and maximum of 50 characters, and unique in the 'users' table.
I want to add the postal code. Problem is, it needs to be different depending the country. That country is in a select:
<select class="select" name="land" id="land" onchange="if (this.selectedIndex) land();">
<option value="-1">--</option>
<option value="c1">Country 1</option>
<option value="c2">Country 2</option>
<option value="c3">Country 3</option>
</select>
In the JS code, I have this:
function land(){
$("select.land").change(function() {
var selectedCountry = $(this).children("option:selected").val();
if(selectedCountry === 'Belgie'){
<?php $postalCode = "'postcode' => array('required' => true,'figures' => true,'max' => 4, 'notlowercase' => true, 'notuppercase' => true, 'notspecial' => true)," ?>
}else if(selectedCountry === 'Nederland'){
<?php $postalCode = "'postcode' => array('required' => true,'figures' => true,'max' => 7, 'notlowercase' => true, 'uppercase' => true, 'notspecial' => true)," ?>
}
});
}
problem is, if I put in just the $postalCode in the validation, like this:
'username' => array('required' => true,'min' => 2,'max' => 50,'unique' => 'users'),
$postalCode,
...
then php gives me an Invalid argument on the foreach, that starts like this:
foreach($rules as $rule => $rule_value) {
Question is, how would I fix this?
--------Update----------- Now I have this:
$land = $_POST['land'];
if($land === 'Belgie' || $land === 'belgie'){
$test = "'postcode' => array('required' => true,'figures' => true,'max' => 4,'notlowercase' => true,'notuppercase' => true, 'notspecial' => true),";
}else if($land === 'Nederland' || $land === 'nederland'){
$test = "'postcode' => array('required' => true,'figures' => true,'max' => 6, 'notlowercase' => true, 'uppercase' => true, 'notspecial' => true),";
}
But still the same error (invalid argument). I think it's because I give a String and it expects an Array, but don't know how to solve this.