Sending an Email within an Editor Table
Sending an Email within an Editor Table
cemlimited
Posts: 36Questions: 9Answers: 0
in Editor
Okay Guys
$aaa =Editor::inst( $db, $table );
$aaa ->on('postCreate', function ($values) {
$from = "email@email.com"; //Change this to whatever
$subject = "Test Subject";
$to = "youremail@youremail.com";
$message = "Hello World";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <youremail@youremail.com>' . "\r\n";
mail($to,$subject,$message,$headers);
});
$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?
This question has an accepted answers - jump to answer
Answers
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?
Allan
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);
$result2->execute();
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
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// 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->process( $_POST )->json();
'''
Sorry - Dont know why it is kicking the last string outside the '''
Okay All.....
I managed to resolve the matter by iterating through the complete Post info...
The information from the submission is 3 levels down....
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!Allan
Thanks Allan. A legend as always...