This topic is locked

Email button for earch record

8/19/2011 8:06:00 AM
PHPRunner General questions
jclabuschagne author

Goodday,
I need an extra field on the list page that contains a php code button. The button must get the Id of the record, and then run code sensitive to the ID of the record.
I would prefer if the button can appear next to each record, but if there isn't a way, the other way would be to select the record, and have just one php code button that extracts the id of the selected record and run the code.
I need this to make an email button, but the button isn't just a simple email button, I use an external php file(via require_once) with MIME classes that I use to format the email with images etc.
So basically I just need to know how to insert a php button for each record, and have that button get the ID of the record, so I can run the external script on it.
I guess that I would somehow use the After record processed event or something like that.
Any help would be much appreciated.

C
cgphp 8/19/2011

Johan,
create an alias for one of the fields in the query section:



SELECT

field_1,

field_2,

field_3,

field_3 as alias_field_3

FROM

your_table


Check the new alias field for the list page only and set it as custom field. Then enter a code like this:

$value = "<input type=\"button\" name=\"email_sender\" value=\"Send email\" id=\"".$data['your_field_id_name']."\" />";


In the javascript OnLoad event of the list page enter this code:

$("input[type='button'][name='email_sender']").click(function(e){

$.ajax({

type: "POST",

url: "you_php_file_name.php",

data: "id="+$(this).attr('id'),

success: function(msg){

alert("Email sent");

}

})

});


You don't need to include your external php file. Call it from the ajax request.
In the external php file enter a code like this:



<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{
//you can access the id field with $_POST['id']
//here the code to send email message

}

?>
T
text 9/14/2011

Edit:
Sergey, please can you delete this. I have solved it.
regards
Richard
------------------------------------------------------------
Not knowing anything about Javascript, how would I need to amend the code below to include two $data fields that can be passed to an external script?
Thanks very much
Richard



Johan,
create an alias for one of the fields in the query section:



SELECT

field_1,

field_2,

field_3,

field_3 as alias_field_3

FROM

your_table


Check the new alias field for the list page only and set it as custom field. Then enter a code like this:

$value = "<input type=\"button\" name=\"email_sender\" value=\"Send email\" id=\"".$data['your_field_id_name']."\" />";


In the javascript OnLoad event of the list page enter this code:

$("input[type='button'][name='email_sender']").click(function(e){

$.ajax({

type: "POST",

url: "you_php_file_name.php",

data: "id="+$(this).attr('id'),

success: function(msg){

alert("Email sent");

}

})

});


You don't need to include your external php file. Call it from the ajax request.
In the external php file enter a code like this:



<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{
//you can access the id field with $_POST['id']
//here the code to send email message

}

?>