I would like to check many rows of the same 2 input fields in a form. The validation should fail if one is empty and the other is not.
I have created an associative array based on several input fields(e_me_id, e_md_number, e_md_id1,e_md_number1, p_me_id,p_md_number...) in a form.
$pattern='(md_number|me_id)';
foreach($_POST as $field => $value) {
$success = preg_match($pattern, $field);
if ($success) {
$validate += [$field => $value];
}
}
result of validate =(
[e_me_id] => 1
[e_md_number] => 111
[e_me_id2] => 2
[e_md_number2] => 222
[p_me_id] => 10
[p_md_number] => 101010
[f_me_id] => 16
[f_md_number] => 161616
[d_me_id] => 18
[d_md_number] => 181818 )
I need some looping php to check that the first/second are both null or both filled... same for third/forth, fifth/sixth... etc etc.
I tried to use prev($validate) and next($validate) but could not get it to work.
Any ideas or a different approach.
Thanks in advance.