Thursday 15 May 2014

phpmailer - Verifying empty data fields before submitting PHP emailer form -


Come on ??? I am working with a PHP mailer and am gathering information submitted by the user. Some input fields are optional, which means that some data fields will be empty. I do not want to print or submit empty lines within the mailer, so I would like to test whether the string is empty or not. If empty, then I want to leave it. For example, in the sample given below, information is collected in the table as before, I want to see if it is empty or do not test $ option1Field and, if it is, leave it Give, as well as $ qty1Field in other words, leave the whole segment.

I do not want to know the correct syntax to know what I'm doing.

Any help much appreciated Thank you.

Bill

  & lt ;? Php $ choice1Field = $ _POST ['choice1']; $ Qty1Field = $ _POST ['qty1']; $ Choice2Field = $ _POST ['choice2']; $ Qty2Field = $ _POST ['qty2']; $ Choice3Field = $ _POST ['Likes 3']; $ Qty3Field = $ _POST ['qty3']; $ Body = & lt; & Lt; & Lt; EOD & lt; Table width = "50%" range = "0" cells = "10" cellpadding = "0" & ​​gt; & Lt; Tr bgcolor = "# F6EFBA" & gt; & Lt; Td width = "80%" align = "left" & gt; $ Choice1 field & lt; / Td> & Lt; TD & gt; $ Qty1Field & lt; / TD & gt; & Lt; / TR & gt; & Lt; Tr bgcolor = "# E8E8FF" & gt; & Lt; Td width = "80%" align = "left" & gt; $ Choice2Field & lt; / Td> & Lt; TD & gt; $ Qty2Field & lt; / TD & gt; & Lt; / TR & gt; & Lt; Tr bgcolor = "# F6EFBA" & gt; & Lt; Td width = "80%" align = "left" & gt; $ Choice3 field & lt; / Td> & Lt; TD & gt; $ Qty3Field & lt; / TD & gt; & Lt; / TR & gt; Etc., etc., etc. & Lt; / Table & gt; The end of the day; $ Headers = "to: $ emailField" "\ r \ n"; $ Headers = "Content-type: text / html" "\ r \ n"; $ Success = mail ($ mailto, $ emailSubject, $ body, $ headers); ? & Gt;    

You can use the isset () function:

Example:

  if (isset ($ _ POST ['choice1']) {// do something with it.}    

No comments:

Post a Comment