0

I've got a form with this text field:

<input name="address2" type="text" value="%%ADDRESS2%%">

on submit, it displays all the data in a confirmation page, and then when you submit the confirmation page it emails me the data.

In the email (maybe in belongs in the confirmation page?), I need it to say:

"if data was entered in that field, then include that data in the email"

How to do?

Edited by Jamesiv1: edit the title

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by phoenix_2000
0

I kind of understand what you want to do..

Is the field a required field? In which, the user MUST enter the data for the email to send?

<?php

    if(!isset($_POST['address']))
    {
       // Create a body WITHOUT the data
       $body = "This is what the email will say without the data";
    }else{
       $data = $_POST['address'];
       $body = "This is what the email will say if there is data.. The data is: $data";
    }

    mail($EMAIL_ADDRESS, 'From: blahblah@blah.com', 'The title', $body);


?>

Something along those lines?

0

No, it's not a required field. It's the second line of an address such as an apartment number.

Here is the line from the form:

<input name="address2" type="text" value="%%ADDRESS2%%">

And here's a chunk of html from the email template with what I think should happen:

<tr>
  <td>
  Postal Address:</td>
  <td>%%ADDRESS1%%<br>    
  <?php
  if user entered data in the "address2" field
  print "%%ADDRESS2%%<br>"
  otherwise, print nothing
  ?>    
  %%CITY%%, %%STATE%% %%ZIP%%<br>
  %%COUNTRY%%</td>
</tr>

Edited by Jamesiv1: edit post

0

What you could do is append to the body of the email if the user filled this field, something like this:

<?php
$body = "this is what the mail starts with";
if (!$_POST['address2'] == null){
    $body = $body . $_POST['adress2'];
}
$body = $body . "this is what the mail ends with";

I don't have the time to boot up my development environment to test it, but using $body += instead of $body = $body .
might also work.

Oh, and i don't know if using and isset() here is a good idea, if i'm not mistaken, a $_POST will always make a field for every form input, even if it's empty (null)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.