jkkenzie Posted September 18, 2011 Share Posted September 18, 2011 I need to validate the POST fields below except a few hidden inputs like User_id & category: They are not huge but i would not like to write for each a line of code like if(empty($_popst['field'])) ... How can simplify this by checking only if they are empty and display a message that lists all fields that were not filled? array('user_id'=>$data['Id'], 'surname'=>$_POST['surname'], 'firstname'=>$_POST['firstname'], 'middlename'=>$_POST['middlename'], 'id_number'=>$_POST['id_number'], 'pin_number'=>$_POST['pin_number'], 'street'=>$_POST['street'], 'estate'=>$_POST['estate'], 'hse_number'=>$_POST['hse_number'], 'town'=>$_POST['town'], 'tele'=>$_POST['tele'], 'mobi'=>$_POST['mobi'], 'work_street'=>$_POST['work_street'], 'work_building'=>$_POST['work_building'], 'company'=>$_POST['company'], 'work_town'=>$_POST['work_town'], 'work_tele'=>$_POST['work_tele'], 'work_fax'=>$_POST['work_fax'], 'cont_surname'=>$_POST['cont_surname'], 'cont_firstname'=>$_POST['cont_firstname'], 'cont_middlename'=>$_POST['cont_middlename'], 'cont_street'=>$_POST['cont_street'], 'cont_building'=>$_POST['cont_building'], 'cont_company'=>$_POST['cont_company'], 'cont_home_tele'=>$_POST['cont_home_tele'], 'cont_office_tele'=>$_POST['cont_office_tele'], 'cont_mobi'=>$_POST['cont_mobi']); Link to comment https://forums.phpfreaks.com/topic/247361-validate-huge-fields/ Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 I'd make two arrays: $non_required_fields = array( 'user_id'=>$data['Id'] ); $required_fields = array( 'surname'=>$_POST['surname'], 'firstname'=>$_POST['firstname'], 'middlename'=>$_POST['middlename'], 'id_number'=>$_POST['id_number'], 'pin_number'=>$_POST['pin_number'], 'street'=>$_POST['street'], 'estate'=>$_POST['estate'], 'hse_number'=>$_POST['hse_number'], 'town'=>$_POST['town'], 'tele'=>$_POST['tele'], 'mobi'=>$_POST['mobi'], 'work_street'=>$_POST['work_street'], 'work_building'=>$_POST['work_building'], 'company'=>$_POST['company'], 'work_town'=>$_POST['work_town'], 'work_tele'=>$_POST['work_tele'], 'work_fax'=>$_POST['work_fax'], 'cont_surname'=>$_POST['cont_surname'], 'cont_firstname'=>$_POST['cont_firstname'], 'cont_middlename'=>$_POST['cont_middlename'], 'cont_street'=>$_POST['cont_street'], 'cont_building'=>$_POST['cont_building'], 'cont_company'=>$_POST['cont_company'], 'cont_home_tele'=>$_POST['cont_home_tele'], 'cont_office_tele'=>$_POST['cont_office_tele'], 'cont_mobi'=>$_POST['cont_mobi'] ); foreach ( $required_fields as $key => $fields ) { if ( isset( $_POST[$key] ) ) { continue; } else { die("$key needs to be field out."); } } $array = array_merge($non_required_fields, $required_fields ); // got them back together. Link to comment https://forums.phpfreaks.com/topic/247361-validate-huge-fields/#findComment-1270353 Share on other sites More sharing options...
jkkenzie Posted September 18, 2011 Author Share Posted September 18, 2011 Great stuff man! Thanks Link to comment https://forums.phpfreaks.com/topic/247361-validate-huge-fields/#findComment-1270363 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 If this worked and you don't need anymore help with this specifically can you mark the topic as solved please? Link to comment https://forums.phpfreaks.com/topic/247361-validate-huge-fields/#findComment-1270367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.