corics15 Posted June 27, 2007 Share Posted June 27, 2007 hello everyone! I have at least 45 fields in my form and only 8 of them are required namely, NAME, GENDER, DATE OF BIRTH, AGE, HEIGHT, WEIGHT, EMAIL AND CONTACT NO. The rest is optional. The problem is, I dont want to include the blank fields which have not been filled up when the SUBMIT button is clicked. I just want the fields which has been filled up to appear in the mail recipient. Could anybody help, please? Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/ Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 give us a bit more code and we can help you but you can try a foreach($_POST as $value) and then just remove the ones you don't one in post Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/#findComment-283645 Share on other sites More sharing options...
corics15 Posted June 27, 2007 Author Share Posted June 27, 2007 hey! thanks for the prompt reply. ummm, the user may fill the fields in random, so I don't have a way to know which fields has been filled up or not... cheers! Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/#findComment-283647 Share on other sites More sharing options...
corics15 Posted June 27, 2007 Author Share Posted June 27, 2007 i understand that I have to use an array, foreach and the if statement, but i don't have any idea how to implement it in code ??? :'(, my head aches... Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/#findComment-283651 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 try this <?php foreach ($_POST as $key => $value){ if ($value != ""){ $emailtext .= $key . " = " .$value ."\n\n"; } } ?> That will do it basically, otherwise deal with them later. Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/#findComment-283652 Share on other sites More sharing options...
corics15 Posted June 27, 2007 Author Share Posted June 27, 2007 i understand that I have to use an array, foreach and the if statement, but i don't have any idea how to implement it in code ??? :'(, my head aches... well, after researching, i found out that: 1. store the field values in an array 2. loop through each values and check if the fields are empty and store in the second array 3. print the values in the the second array using the list command but i don't have any idea how to implement it in code... function DoStripSlashes($FieldValue) { if ( get_magic_quotes_gpc() ) { if (is_array($FieldValue) ) { return array_map('DoStripSlashes', $FieldValue); } else { return stripslashes($FieldValue); } } else { return $FieldValue; } } /* filterchars and dostripslashes were ommitted in this line */ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ClientIP = $_SERVER['REMOTE_ADDR']; } $FTGfirst_name = DoStripSlashes( $_REQUEST['first_name'] ); $FTGlast_name = DoStripSlashes( $_REQUEST['last_name'] ); $FTGgender = DoStripSlashes( $_REQUEST['gender'] ); $FTGany_date_month = DoStripSlashes($_REQUEST['any_date_month']); $FTGany_date_day = DoStripSlashes($_REQUEST['any_date_day']); $FTGany_date_year = DoStripSlashes($_REQUEST['any_date_year']); $FTGage = DoStripSlashes( $_REQUEST['age'] ); $FTGheight = DoStripSlashes( $_REQUEST['height'] ); $FTGweight = DoStripSlashes( $_REQUEST['weight'] ); $FTGreligion = DoStripSlashes( $_REQUEST['religion'] ); $FTGcivil_status = DoStripSlashes( $_REQUEST['civil_status'] ); $FTGpassport_no = DoStripSlashes( $_REQUEST['passport_no'] ); $FTGcoll_univ = DoStripSlashes( $_REQUEST['coll_univ'] ); $FTGcoll_univ_course = DoStripSlashes( $_REQUEST['coll_univ_course'] ); $FTGcoll_graduate = DoStripSlashes( $_REQUEST['coll_graduate'] ); $FTGtech_voc = DoStripSlashes( $_REQUEST['tech_voc'] ); $FTGtech_voc_course = DoStripSlashes( $_REQUEST['tech_voc_course'] ); $FTGtech_voc_graduate = DoStripSlashes( $_REQUEST['tech_voc_graduate'] ); $FTGhigh_sch = DoStripSlashes( $_REQUEST['high_sch'] ); $FTGco_name = DoStripSlashes( $_REQUEST['co_name'] ); $FTGco_name_add = DoStripSlashes( $_REQUEST['co_name_add'] ); $FTGco_prod = DoStripSlashes( $_REQUEST['co_prod'] ); $FTGco_jobdesc = DoStripSlashes( $_REQUEST['co_jobdesc'] ); $FTGco_name2 = DoStripSlashes( $_REQUEST['co_name2'] ); $FTGco_name_add2 = DoStripSlashes( $_REQUEST['co_name_add2'] ); $FTGco_prod2 = DoStripSlashes( $_REQUEST['co_prod2'] ); $FTGco_jobdesc2 = DoStripSlashes( $_REQUEST['co_jobdesc2'] ); $FTGco_name3 = DoStripSlashes( $_REQUEST['co_name3'] ); $FTGco_name_add3 = DoStripSlashes( $_REQUEST['co_name_add3'] ); $FTGco_prod3 = DoStripSlashes( $_REQUEST['co_prod3'] ); $FTGco_jobdesc3 = DoStripSlashes( $_REQUEST['co_jobdesc3'] ); $FTGco_name4 = DoStripSlashes( $_REQUEST['co_name4'] ); $FTGco_name_add4 = DoStripSlashes( $_REQUEST['co_name_add4'] ); $FTGco_prod4 = DoStripSlashes( $_REQUEST['co_prod4'] ); $FTGco_jobdesc4 = DoStripSlashes( $_REQUEST['co_jobdesc4'] ); $FTGco_name5 = DoStripSlashes( $_REQUEST['co_name5'] ); $FTGco_name_add5 = DoStripSlashes( $_REQUEST['co_name_add5'] ); $FTGco_prod5 = DoStripSlashes( $_REQUEST['co_prod5'] ); $FTGco_jobdesc5 = DoStripSlashes( $_REQUEST['co_jobdesc5'] ); $FTGco_name6 = DoStripSlashes( $_REQUEST['co_name6'] ); $FTGco_name_add6 = DoStripSlashes( $_REQUEST['co_name_add6'] ); $FTGco_prod6 = DoStripSlashes( $_REQUEST['co_prod6'] ); $FTGco_jobdesc6 = DoStripSlashes( $_REQUEST['co_jobdesc6'] ); $FTGspec_skills = DoStripSlashes( $_REQUEST['spec_skills'] ); $FTGmach_types = DoStripSlashes( $_REQUEST['mach_types'] ); $FTGemail = DoStripSlashes( $_REQUEST['email'] ); $FTGcontact_no = DoStripSlashes( $_REQUEST['contact_no'] ); well here is the code for you guys to check...hope you can help me out...thanks... Link to comment https://forums.phpfreaks.com/topic/57359-i-dont-want-to-include-blank-form-fields-when-emailed/#findComment-283880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.