SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Email Form Notofication to only include populated fields.

    I am using the Advanced Forms addon with Concrete5 and I have used it to build a rather long form. The client only wants the email notification that gets sent to him to include the fields that have been filled out. I contacted the developer of Advanced Forms and he gave me an answer. Basically change this line of code:

    if(!$field->excludeFromEmail) {
    to
    if((!$field->excludeFromEmail) && ($this->answers[$field->ffID]['value'] != '')) {

    The problem is with dropdowns. In order to make the first entry in a dropdown not have a selection made, I need to either create an empty entry or use generic text. For example:

    non-breaking space character
    1
    2
    3
    etc

    OR

    --Please Select a Quantity--
    1
    2
    3
    etc

    For whatever reason, the code above doesn't recognize the non breaking space as an empty field. So I'm trying to figure out how to get an OR statement in the code. I tried:

    if((!$field->excludeFromEmail) && ($this->answers[$field->ffID]['value'] != '') OR ($this->answers[$field->ffID]['value'] != '--Please Select a Quantity--')) {
    and
    if((!$field->excludeFromEmail) && ($this->answers[$field->ffID]['value'] != '') || ($this->answers[$field->ffID]['value'] != '--Please Select a Quantity--')) {

    Neither of these options worked either.

    So my question, how do I create a proper OR statement to get this to work? Here's more of the function:

    public function sendNotification($to) {

    $f = sixeightform::getByID($this->fID);
    $fields = $f->getFields();

    $emailData = '';

    if($f->properties['sendData']) {
    foreach($fields as $field) {
    // if(!$field->excludeFromEmail) {
    if((!$field->excludeFromEmail) && ($this->answers[$field->ffID]['value'] != '')) {
    if($field->type == 'Credit Card') {
    $emailData .= $field->label . "\nXXXX\n\n";
    } elseif(($field->type == 'File Upload') || ($field->type == 'File from File Manager')) {
    $file = File::getByID($this->answers[$field->ffID]['value']);
    $fv = $file->getApprovedVersion();
    $emailData .= strip_tags($field->label) . "\n";
    $emailData .= BASE_URL . $fv->getRelativePath() . "\n\n";
    } else {
    $emailData .= strip_tags($field->label) . "\n";
    $emailData .= strip_tags($this->answers[$field->ffID]['value']) . "\n\n";
    }
    }
    }

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Change the || in &&
    PHP Code:
    if((!$field->excludeFromEmail) && ($this->answers[$field->ffID]['value'] != '') && ($this->answers[$field->ffID]['value'] != '--Please Select a Quantity--')) { 
    You want the value to be different from '' AND different from '--Please Select a Quantity--'

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. That worked.


Bookmarks

Posting Permissions

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