Results 1 to 4 of 4

Thread: [RESOLVED] PHP-Don't include blank form fields when emailed

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Resolved [RESOLVED] PHP-Don't include blank form fields when emailed

    Hello, I have a simple HTML form asking for multiple user info. Most of the form fields are not required to be filled out. The form fields are then sent through PHP to then be emailed to me.

    My question: How do I not include the blank form fields when emailed?!
    My requirement: I want the resulting email to have a nice layout as you can see from here:
    Code:
    $email_message .= "Attendance: ".clean_string($attendance)."\n\n";
    	$email_message .= "First Name: ".clean_string($first_name)."\n";
    	$email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= ($first_name)."'s food restrictions: ".clean_string($other_allergies1)."\n\n";
    The result in my email:
    Attendance: Wedding_only

    First Name: Joe
    Last Name: Smith
    Joe's food restrictions: none
    Oh! And I'm a total noob. I know just enough to modify existing code and just enough to get myself into trouble. So if you do reply, please spell it out step-by-step or just show me my code=modified.
    Thank you for your time!


    My Code:
    Code:
    $attendance = $_POST['attendance']; // required
    	$first_name = $_POST['guest1-fn']; // required
    	$last_name = $_POST['guest1-ln']; // required
    	$other_allergies1 = $_POST['other_allergies1']; // not required
    	$guest2_fn = $_POST['guest2-fn']; // not required
    	$guest2_ln = $_POST['guest2-ln']; // not required
    	$other_allergies2 = $_POST['other_allergies2']; // not required
    	$guest3_fn = $_POST['guest3-fn']; // not required
    	$guest3_ln = $_POST['guest3-ln']; // not required
    	$other_allergies3 = $_POST['other_allergies3']; // not required
    	$guest4_fn = $_POST['guest4-fn']; // not required
    	$guest4_ln = $_POST['guest4-ln']; // not required
    	$other_allergies4 = $_POST['other_allergies4']; // not required
    	$guest5_fn = $_POST['guest5-fn']; // not required
    	$guest5_ln = $_POST['guest5-ln']; // not required
    	$other_allergies5 = $_POST['other_allergies5']; // not required
    	$guest6_fn = $_POST['guest6-fn']; // not required
    	$guest6_ln = $_POST['guest6-ln']; // not required
    	$other_allergies6 = $_POST['other_allergies6']; // not required
    	$hotel = $_POST['hotel']; // not required
    	$transportation = $_POST['transportation']; // not required
    	$rentalshare = $_POST['rentalshare']; // not required
    	$taxishare = $_POST['taxishare']; // not required
    	$tigers = $_POST['tigers']; // not required
    	$email_from = $_POST['email']; // not required
    	
    
    	$email_message .= ($first_name)."'s RSVP.\n\n";
    	
    	function clean_string($string) {
    	  $bad = array("content-type","bcc:","to:","cc:","href");
    	  return str_replace($bad,"",$string);
    	}
       
    	$email_message .= "Attendance: ".clean_string($attendance)."\n\n";
    	$email_message .= "First Name: ".clean_string($first_name)."\n";
    	$email_message .= "Last Name: ".clean_string($last_name)."\n";
    	$email_message .= ($first_name)."'s food restrictions: ".clean_string($other_allergies1)."\n\n";
    	$email_message .= "Guest 2 First Name: ".clean_string($guest2_fn)."\n";
    	$email_message .= "Guest 2 Last Name: ".clean_string($guest2_ln)."\n";
    	$email_message .= ($guest2_fn)."'s food restrictions: ".clean_string($other_allergies2)."\n\n";
    	$email_message .= "Guest 3 First Name: ".clean_string($guest3_fn)."\n";
    	$email_message .= "Guest 3 Last Name: ".clean_string($guest3_ln)."\n";
    	$email_message .= ($guest3_fn)."'s food restrictions: ".clean_string($other_allergies3)."\n\n";
    	$email_message .= "Guest 4 First Name: ".clean_string($guest4_fn)."\n";
    	$email_message .= "Guest 4 Last Name: ".clean_string($guest4_ln)."\n";
    	$email_message .= ($guest4_fn)."'s food restrictions: ".clean_string($other_allergies4)."\n\n";
    	$email_message .= "Guest 5 First Name: ".clean_string($guest5_fn)."\n";
    	$email_message .= "Guest 5 Last Name: ".clean_string($guest5_ln)."\n";
    	$email_message .= ($guest5_fn)."'s food restrictions: ".clean_string($other_allergies5)."\n\n";
    	$email_message .= "Guest 6 First Name: ".clean_string($guest6_fn)."\n";
    	$email_message .= "Guest 6 Last Name: ".clean_string($guest6_ln)."\n";
    	$email_message .= ($guest6_fn)."'s food restrictions: ".clean_string($other_allergies6)."\n\n";
    	$email_message .= "Hotel/Accomodations: ".clean_string($hotel)."\n\n";
    	$email_message .= "Transportation: ".clean_string($transportation)."\n";
    	$email_message .= "Rental Car: ".clean_string($rentalshare)."\n";
    	$email_message .= "Taxi: ".clean_string($taxishare)."\n\n";
    	$email_message .= "Tigers Game: ".clean_string($tigers)."\n\n";
    	$email_message .= "Email: ".clean_string($email_from)."\n";
    	
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    Last edited by diedrichg; Apr 18th, 2010 at 11:49 PM. Reason: formatting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width