php - How to drop empty responses in an array of fields? -
i've got php script take answers referral form , send email client (below). client has asked questions have been answered sent them. how can strip out fields empty email?
$from = $_request['email'] ; $name = $_request['name'] ; $headers = "from: $from"; $subject = "web contact data-medical referral"; $fields = array(); $fields{"referrer"} = "referral source"; $fields{"referraldate"} = "date of referral"; $fields{"filenumber"} = "file number"; $fields{"hearingdate"} = "hearing date"; $fields{"legalfirm"} = "legal firm"; $fields{"address"} = "legal firm address"; $fields{"plantiffattorney"} = "plantiff attorney"; $fields{"plantiffaddress"} = "plantiff attorney address"; $fields{"plantifftelephone"} = "plantiff attorney telephone"; $fields{"plantiffemail"} = "plantiff attorney email"; $fields{"defenceattorney"} = "defence attorney"; $fields{"defenceaddress"} = "defence attorney address"; $fields{"defencetelephone"} = "defence attorney telephone"; $fields{"defenceemail"} = "defence attorney email"; $fields{"lawclerk"} = "legal assistant/law clerk"; $fields{"lawclerktelephone"} = "legal assistant/law clerk telephone"; $fields{"lawclerkemail"} = "legal assistant/law clerk email"; $fields{"insurancecompany"} = "name of insurance company"; $fields{"insuranceaddress"} = "insurance company address"; $fields{"adjuster"} = "adjuster name"; $fields{"adjusternumber"} = "adjuster telephone"; $fields{"adjusterfax"} = "adjuster fax"; $fields{"adjusteremail"} = "adjuster email"; $fields{"claimnumber"} = "claim number"; $fields{"claimantname"} = "claimant name"; $fields{"gender"} = "gender"; $fields{"dateofbirth"} = "date of birth"; $fields{"claimantaddress"} = "claimant address"; $fields{"claimantcity"} = "claimant city"; $fields{"claimantpostal"} = "claimant postal code"; $fields{"claimanttelephone"} = "claimant telephone"; $fields{"lossdate"} = "date of loss"; $fields{"injuries"} = "injuries"; $fields{"diagnosis"} = "diagnosis"; $fields{"reportaddress"} = "report address"; $fields{"transportation"} = "transportation required"; $fields{"translation"} = "translation required"; $fields{"language"} = "language"; $fields{"abilitiesevaluation"} = "abilities evaluation"; $fields{"occupationaltherapist"} = "legal ime-occupational therapist"; $fields{"rheumatologist"} = "legal ime-rheumatologist"; $fields{"chiropractic"} = "legal ime-chiropractic"; $fields{"opthamologist"} = "legal ime-opthamologist"; $fields{"socialworker"} = "legal ime-social worker"; $fields{"dental"} = "legal ime-dental"; $fields{"optomertrist"} = "legal ime-optometrist"; $fields{"slp"} = "legal ime-slp"; $fields{"endocrinologist"} = "legal ime-endocrinologist"; $fields{"orthopedic"} = "legal ime-orthopedic surgeon"; $fields{"tsa"} = "legal ime-tsa"; $fields{"ent"} = "legal ime-ent"; $fields{"pediatrician"} = "legal ime-pediatrician"; $fields{"vascularsurgeon"} = "legal ime-vascular surgeon"; $fields{"gastroenterologist"} = "legal ime-gastroenterologist"; $fields{"physician"} = "legal ime-physician"; $fields{"vocationalevaluation"} = "legal ime-vocational evaluation"; $fields{"internalmedicine"} = "legal ime-internal medicine"; $fields{"physiatrist"} = "legal ime-physiatrist"; $fields{"legalfilereview"} = "legal file review"; $fields{"jobanalysis"} = "legal ime-job analysis/wsa"; $fields{"physiotherapist"} = "legal ime-physiotherapist"; $fields{"lifecare"} = "life care plan"; $fields{"neurologist"} = "legal ime-neurologist"; $fields{"psychiatrist"} = "legal ime-psychiatrist"; $fields{"lifecarereview"} = "life care plan review"; $fields{"neuropsychologist"} = "legal ime-neuropsychologist"; $fields{"psychologist"} = "legal ime-psychologist"; $fields{"other"} = "other"; $fields{"otherrequired"} = "service"; $fields{"neurosurgeon"} = "legal ime-neurosurgeon"; $fields{"psychovocational"} = "legal ime-pyschovocational"; $fields{"comments"} = "comments"; $body="referral info:\n\n"; foreach($fields $a => $b) { $body .= sprintf("%20s:%s\n",$b,$_request[$a]); } if(empty($fields)) { echo 'please fill in submission form'; return false; } $send = mail($email, $subject, $body); if ($send){ print "thank you!"; }else{ print "oops!"; }
check whether field empty before adding mail.
foreach($fields $a => $b) { if (!empty($_request[$a])) { $body .= sprintf("%20s:%s\n",$b,$_request[$a]); } }