Sending an Email within an Editor Table

Sending an Email within an Editor Table

cemlimitedcemlimited Posts: 32Questions: 8Answers: 0

Okay Guys

$aaa =Editor::inst( $db, $table );

$aaa ->on('postCreate', function ($values) {
               $from = ""; //Change this to whatever 
        $subject = "Test Subject";
                $to = ""; 
                $message = "Hello World";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        // More headers
        $headers .= 'From: <>' . "\r\n";

$aaa->process( $_POST )->json();

When this is added, it is throwing a JSON problem

How do I manage this so that the function does not impact the JSON?


  • allanallan Posts: 56,849Questions: 1Answers: 9,035 Site admin

    Nothing immediately obvious in that code - the syntax is valid. Is the response from the server the same as we discussed by e-mail - zero length empty?

    If you check the web-server's error logs, is there anything shown there? What web-server are you using?


  • cemlimitedcemlimited Posts: 32Questions: 8Answers: 0
    edited July 1

    Okay - So I have identified that the Code is not causing an error until i try to use the information posted within the $message.

    I then used $vals = $_POST['action'];

    and used $vals within the message and it worked...returning the "Create" value.....

    So the question is how to access the submitted values.....

    Tried $vals = $_POST['values] and then made sure to have them within the USE() section of the function.....It simply returns 1 when I use print_r($vals)


    $vals = $_POST['values'];

    $result2 = $db->prepare($fieldquery);

    foreach ($result2 as $row) {
    $fields[] =$row['Field'];

    $excludes = array("created_by","updated_by","created_date","accepted_date","completed_date","updated_date");

    $selects = array("task","skill","action");
    $selectstable = array("task","skills","registration");
    $selectssource = array("id","id","id");
    $selectslabels = array("task","skill","username");
    $hyperlinks = array("id");

    $dates = array("target_date");

    $boolean = array("fee");

    $range = array("skill_level");

    // DataTables PHP library
    include( $_SERVER["DOCUMENT_ROOT"]."/DTEditor/lib/DataTables.php" );

    $db->sql("SET names 'utf8'");

    // Alias Editor classes so they are easy to use

    // Build our Editor instance and process the data coming from _POST

    $aaa =Editor::inst( $db, $table );
    $aaa->where('brief', $brief);

    foreach(array_diff($fields,$excludes, $selects, $dates, $boolean) as $field){
    $aaa ->field(Field::inst( $table.".".$field));

    $cycle = 0;

    foreach($selects as $select){
    $aaa ->field(Field::inst($table.'.'.$select)->options( Options::inst()->table( $selectstable[$cycle] )->value( $selectssource[$cycle] )->label( $selectslabels[$cycle] ))->validator( Validate::dbValues()));
    $aaa ->field(Field::inst( $selectstable[$cycle].'.'.$selectslabels[$cycle]));
    $aaa ->leftJoin( $selectstable[$cycle],$selectstable[$cycle].'.'.$selectssource[$cycle], '=', $table.'.'.$select );
    $cycle = $cycle + 1;

    foreach($dates as $date){
    $aaa ->field(Field::inst($table.'.'.$date)->validator( Validate::dateFormat('Y-m-d'))->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )->setFormatter( Format::dateFormatToSql('Y-m-d' ) ));

    foreach($boolean as $boo){
    $aaa ->field(Field::inst($table.'.'.$boo)->setFormatter( function ( $val, $data, $opts ) {return ! $val ? 0 : 1;} ));

    $aaa->on('postCreate', function ($editor, $id, $values, $row) use ($briefname, $vals, $brief, $projectname)  {
        $from = ""; 
        $subject = "AscentXD registration";
        $to = ""; 
        $message = "
            Congratulations!<br> <br>
            A New task has been created on <br><br>".$projectname."<br>".print_r($vals)."<br>".$briefname.".<br><br> Access Here: <a href='".$brief."'></a> for your attention<br> <br> 
            <br>Kind Regards, <br><br>Ascent Admin<br><br>
        //$message = print_r($values);
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        // More headers
        $headers .= 'From: <>' . "\r\n";
        return '';
    } );

    $aaa->process( $_POST )->json();

  • cemlimitedcemlimited Posts: 32Questions: 8Answers: 0

    Sorry - Dont know why it is kicking the last string outside the '''

  • cemlimitedcemlimited Posts: 32Questions: 8Answers: 0

    Okay All.....

    I managed to resolve the matter by iterating through the complete Post info...

    The information from the submission is 3 levels down....

    $vals = array();
    foreach ($_POST as $key => $value) {
        foreach ($value as $key1 => $value1) {
            foreach ($value1 as $key2 => $value2) {
                foreach ($value2 as $key3 => $value3) {
                    $vals[$key3] =  $value3;
  • allanallan Posts: 56,849Questions: 1Answers: 9,035 Site admin

    You need to use a back tick for the syntax highlighting, rather than an apostrophe.

    It might have clicked for me why it wasn’t working before - are you using joined tables here - i.e. field names with table.column syntax? If so, in your postCreate` event handler you’d need to use:


    Rather than just $values[‘field’]. I’m not certain about that, but guessing due to the triple loop you have there. Hopefully, if that works, it should make the code a lot cleaner!


Sign In or Register to comment.