Email Notification in Form

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

Hi April,

There are a couple of small errors that are stopping this form working correctly.

The reason that your place holders are empty is that on line 114 of form.php you have this line:

$_REQUEST      = array();

This is unsetting all of the items in your request array, then on line 121 when you're creating your place holders after the request array has been removed. If you remove the line $_REQUEST = array(); your placeholders should send. 

The second issue is that the mysql_insert_id() contains the num value that was inserted into photocontests_new, but the link in your placeholders is going to the section calendar. I think you just need to change the link to go to photocontests_new on line 125, and the link should work.

$GLOBALS['SETTINGS']['adminUrl'] . "?menu=photocontests_new&action=edit&num=" . mysql_insert_id(),

Let me know if you have any questions.

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

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