0

I am by no means a PHP expert. I barely scratch the surface, so please forgive my post. However, after much searching, I can't seem to find the answer to my question.

Essentially, I have a contact form with many questions (http://www.tabsfm.com/contact/quote/). Not all questions need answers. so the problem I have is that when the email comes through, all questions are displayed including the ones with no answers.

Is it possible to only post to the email the questions which have received an answer, ignoring any blank responses?

Rather than post the whole contact form, perhaps someone could help provide an example for the following segment:

HTML

Department/Organisation Size: 
    <select  name="Size" class="hear">
    <option value="000">Please Select</option>
    <option value="1-5">1-5</option>
    <option value="5-10">5-10</option>
    <option value="10-20">10-20</option>
    <option value="20-50">20-50</option>
    <option value="50-100">50-100</option>
    <option value="100+">100+</option>
    </select>

PHP

$size = $_POST['Size']; and   

$response = "$todayis [EST] \n
 Company Size: $size \n

I hope you guys can help.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
  • Let's see if I've got this straight - you only want to show fields that have some user selection in the e-mail? – Pawel J. Wal Aug 27 '13 at 11:40
  • Yeah, basically all questions which have not received an answer should be excluded from the email. Leaving only those which have received questions, thus making the email more direct. Thanks for your help. – user2721238 Aug 27 '13 at 11:52

1 Answers1

2

For your (somewhat limited) example, you could approach it like so:

$size = $_POST['Size'];
$response = ""; // Whatever the beginning of your message needs to be

if($size != "000") // your value for not-selected
{
    $response .= "Company Size: $size \n";
}

// repeat for other fields

The repetition for other fields could be achieved with arrays and foreach easier than creating an if block for each field in the form (it definitely is sizable), but not knowing the actual code I can't suggest much.

With checkbox fields, we need to check whether the value is set, instead of the actual value. For your example, something like this:

if(isset($_POST['schedulling']))
{
     $response .= "'schedulling' is checked \n";
}

If you need to read the value, you can do it identically as above, by referencing $_POST['name_of_field']. The rule of thumb is that the $_POST field related to a checkbox returns true from isset only when the checkbox is checked, and false otherwise.

Pawel J. Wal
  • 1,166
  • 1
  • 11
  • 24
  • Sorry, one more question. How will this work for check boxes. i.e. to only Post check boxes that have been checked and exclude those that haven't? This is the form field... – user2721238 Aug 27 '13 at 12:38
  • I've added a snippet for your example. For more general answers, please refer to this question: http://stackoverflow.com/questions/2268887/how-do-i-see-which-checkbox-is-checked – Pawel J. Wal Aug 28 '13 at 07:02