Email Notification in Form

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 4, 2014   (RSS)

Hello,

I am using the email smtp setup that is available now in the CMS settings. I have included the code in one of my forms to send an email when a form is submitted and I have set up a special email template. I am just having two issues. Here is my code:

 // send message

      $placeholders = array(
'user.email'       => $_REQUEST['email'],
'user.fullname'    => $_REQUEST['name'],
'content'          => $_REQUEST['content'],
'contestAdminUrl'  => $GLOBALS['SETTINGS']['adminUrl'] . "?menu=photocontests_new",

      );

       // email admin

      $errors = sendMessage(wsc_emailTemplate_loadFromDB(array(
'template_id'      => 'ADMIN-ENTRY-ADDED',
'placeholders'     => $placeholders,

      )));

      if ($errors) { die("Error sending message: $errors\n\nPlease let us know about this error!"); }

  }

  }  

1). In this url: 'contestAdminUrl'  => $GLOBALS['SETTINGS']['adminUrl'] . "?menu=calendar&action=edit&num=" . mysql_insert_id(),

How do I pull in the record num so it goes directly to the correct entry to edit? 

2). When I tested the form, the email gets sent to me with no issue. The issue is that the fields that I put in the the email template, #user.email# and #user.name# and #content#  are not pulling in any of the data into the sent email. I have included a screen shot of my email template and email that was sent. I have also included my form page with code.

Thanks,

April

Attachments:

emialtemplate.jpg 379K

email.jpg 119K

form.php 19K

Greg,

Thank you for your help.  It is all working except for the url.

I had actually copied and pasted the table name and copied the wrong one (calendar). I am using the correct url now but it returns a 0 instead of the actual id/record number. 

Here is what comes up now:

http://www.charlotteparent.com/cmsadmin/admin.php?menu=photocontests_new&action=edit&num=0

Is there anyway to fix that?

Thanks!

April

By gregThomas - March 4, 2014

Hi April,

It might be that as you've already called mysql_insert_id(), the last inserted value might not be stored in in any more when you call it a second time. You could try changing your code to this between lines 105 and 125:

  mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $recordNum = mysql_insert_id();

      // adopt temp uploads
      adoptUploads($tableName, $preSaveTempId, $recordNum);
      removeExpiredUploads(); // erase old expired uploads

      // display thanks message and clear form
      $errorsAndAlerts = "Thanks, we've added your record!";
      $_REQUEST      = array();
      $preSaveTempId = uniqid('x');  

    // send message

      $placeholders = array(
'user.email'       => $_REQUEST['email'],
'user.fullname'    => $_REQUEST['name'],
'content'          => $_REQUEST['content'],
'contestAdminUrl'  => $GLOBALS['SETTINGS']['adminUrl'] . "?menu=$tableName&action=edit&num=" . $recordNum,

So I've removed the line that resets the $recordNum value to null, and I'm using that value on the end of the contestAdminUrl value. 

Another way around this issue would be to insert the data using CMS Builders mysql_insert function:

    if (!@$errorsAndAlerts) {
      $insertArray = array(
        'createdDate'      => date('Y-m-d H:i:s'),
        'createdByUserNum' => $CURRENT_USER['num'],
        'updatedDate'      => date('Y-m-d H:i:s'),
        'updatedByUserNum' => $CURRENT_USER['num'] ),
        'date'             => date('Y-m-d H:i:s'),
        'hidden'           =>'1',
        'name'             => $_REQUEST['name'],
        'content'          => $_REQUEST['content'],
        'email'            => $_REQUEST['email'],
        'category'         => $_REQUEST['category'] ,
        'title'            => $_REQUEST['title'],
      );
      $recordNum = mysql_insert($tableName, $insertArray, true);

      // adopt temp uploads
      adoptUploads($tableName, $preSaveTempId, $recordNum);
      removeExpiredUploads(); // erase old expired uploads

      // display thanks message and clear form
      $errorsAndAlerts = "Thanks, we've added your record!";
      $preSaveTempId = uniqid('x');
  

    // send message
    $placeholders = array(
     'user.email'       => $_REQUEST['email'],
     'user.fullname'    => $_REQUEST['name'],
     'content'          => $_REQUEST['content'],
     'contestAdminUrl'  => $GLOBALS['SETTINGS']['adminUrl'] . "?menu=$tableName&action=edit&num=" . $recordNum,
    );

The good thing about this function is it automatically parses the data to make it safe for MySQL, and if you pass in true as the third value, it will automatically insert a default value into any fields with missing data.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com