This topic is locked

Adding Button to View Page

5/25/2011 5:39:04 PM
PHPRunner General questions
N
nti author

Hi All,
I would like to add a button to the View Page that will send the data/record (that is currently being viewed) via email.
Any and all suggestions, feedback, code examples are greatly appreciated.
Kindest Regards,

Mike

Sergey Kornilov admin 5/25/2011

Check this article:

http://xlinesoft.com/blog/2011/04/28/taming-the-beast-events-buttons-and-code-snippets/
Insert PHP/ASP code snippet->Session variables->Example 1. It explains how to access field values on View/Edit pages from code snippet/button.

Jessica 5/25/2011

I have read the blog: http://xlinesoft.com/blog/2011/04/28/taming-the-beast-events-buttons-and-code-snippets/
I can not grasp the example. Are there additional modifications required in addition to the ones marked below in red?
Button to send email on list page with records selected.
Which fields are required to be modified for below code to work?

I have modified only those colored red.
'Client Before' and 'Client After' is blank
Code below on 'Server'
-----------code

$email_msg = "";

$email_msg.= "List of records";

foreach($keys as $idx=>$val)

{

$email_msg.= "Record: ".($idx+1)."\r\n";

//select values from TableName based on $val["ID1"]

$tblName = $dal->Table("");

$rstmp = $tblName->Query("ID1=".$val["ID1"],"");

$datatmp = db_fetch_array($rstmp);

$email_msg.= "FieldName1: ".$datatmp["[color="#FF0000"]FieldName1"]."\r\n";

$email_msg.= "FieldName2: ".$datatmp["."\r\n";

$email_msg.= "\r\n";

}

//send email

$email="[color="#FF0000"]test@test.com";

$subject="Sample subject";

runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $email_msg));
-----------code

N
nti author 5/26/2011

I have also read the blog: http://xlinesoft.com...-code-snippets/
Searched the forum for buttons + email.
Searched for email.
Read the help file.
Read the blog.
And I can not get a button to do anything except look pretty on my webpage... unless redirect to cnn.com counts as something.
Feedback is welcomed and help feedback is very welcomed. Thanks.
Why should it be so difficult to make a button and insert?:



//********** Send email with new data ************
$email="--rbegin--test@test.com--rend--";

$from="--rbegin--admin@test.com--rend--";

$msg="";

$subject="--rbegin--New data record--rend--";
foreach($values as $field=>$value)

{

if(!IsBinaryType(GetFieldType($field)))

$msg.= $field." : ".$value."\r\n";

}



$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
J
Jane 5/26/2011

Hi,
here is a sample with comments:

$email="test@test.com";

$from="admin@test.com";

$msg="";

$subject="New data record";
//select data from database based on the ID of viewed record

global $dal;

$dal_table = $dal->Table("TableName");

$rstmp = $dal_table->Query("KeyField=".$keys["KeyField"],"");

$values = db_fetch_array($rstmp);
foreach($values as $field=>$value)

{

if(!IsBinaryType(GetFieldType($field)))

$msg.= $field." : ".$value."\r\n";

}



$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
//save resulted message

if(!$ret["mailed"])

$result["txt"] = $ret["message"];

else

$result["txt"] = "email was sent.";



where KeyField is your actual filed name, TableName is your actual table name.
Then you can print resulted text in the 'Client after' section:

var message = result["txt"];

ctrl.setMessage(message);
N
nti author 5/26/2011

Thank you Jane.
I followed your example and made modifications to:

  1. Table("TableName"); >> Table("MY TABLE NAME");
  2. Query("KeyField=".$keys["KeyField"],""); >> Query("My_Actual_Primary_Key_Field=".$keys["My_Actual_Primary_Key_Field"],"");
  3. ALSO TRIED: >> Query("KeyField=".$keys["My_Actual_Primary_Key_Field"],"");
    I also modified the email to and from address correctly.
    The button is non-responsive. I do not get no response whatsoever unless I use Firefox with Firebug options, I get: 500 Internal Server Error 232ms.
    POST:

    Parametersapplication/x-www-form-urlencoded

    isManyKeys 1

    keys {"0":"4813","1":"4814"}

    params {"buttId":"Email_selected","rndVal":1306442738712}

    Source

    params={"buttId"%3A"Email_selected","rndVal"%3A1306442738712}&keys={"0"%3A"4813","1"%3A"4814"}&isManyKeys=1
    Any thoughts you may share would be appreciated. Thank you.