forms - PHP Return text field data only if box is checked -
i'm creating simple email order form, php skills lacking. have 4 text fields, , want them returned if checkbox selected
<input type="checkbox" class="checks" name="cards" id="cards" value="yes" /> business cards <label for="cardname1">name (exactly should appear on card): </label><input type="text" name="cardname1" id="cardname1"> <label for="title1">title: </label><input type="text" name="title1" id="title1"> <label for="phone1">phone: </label><input type="text" name="phone1" id="phone1"> <label for="fax1">fax: </label><input type="text" name="fax1" id="fax1">
i'm returning
$body = "from: $name\n e-mail: $email\n phone:\n $phone";
from part of form. simplest way include additional data if box checked? ideally, i'd combine data 1 variable
$carddata = $cardname1, $title1, $phone1, $fax1
just check see if checkbox checked. if so, append values $body
. used little "trick" implode()
simplifies bit:
if ($cards === 'yes') { // make sure checkbox ichecked. need put real value here. $body .= "\n " . implode("\n ", array($cardname1, $title1, $phone1, $fax1)); }
Comments
Post a Comment