This topic is locked

email Button

1/10/2008 11:10:59 AM
PHPRunner General questions
G
Greeham author

Is it possible to have a button that acts like a before record added event?
I have a form that gets updated and once completed requires to be emailed to a set address and having a button that is pushed and emails the contents of the form.
Thanks,

J
Jane 1/11/2008

Hi,
where do you want to place email button: on the add/edit or list pages?

G
Greeham author 1/11/2008

Hi Jane,
The Edit page is possible.
Many thanks,
Graham

J
Jane 1/11/2008

Graham,
one of easiest way to send email is to add some code to the After record updated event on the Events tab. Use Send email with new data action as a sample.

Also you can change button caption to Save and send email on the edit page on the Visual Editor tab.

G
Greeham author 1/11/2008

Hi Jane,
I understand that, but the record will be require to be updated a few times before the email requires to be sent. Won't doing as you suggested email it every time it is updated?
Thanks,
Graham

J
Jane 1/11/2008

Graham,
you can do the following:

  1. add custom event (Insert PHP code snippet option) on the Edit page on the Visual Editor tab.

    Here is a sample:
    echo "<INPUT class=button type=button value=&nbsp;&nbsp;send email&nbsp;&nbsp; onclick='window.location=\"TableName_edit.php?editid1=".$_REQUEST["editid1"]."&mail=yes\"'>";


2. then add this code to the Edit page: before process event on the Events tab:

if ($_REQUEST["mail"]=="yes")

{

//send email here
//** Redirect to another page ****

header("Location: TableName_list.php");

exit();

}

L
laonian 1/16/2008

Thanks, Jane. I tested your codes and it works well.
Still found two problems:

  1. The "send email" button is not shown completely. Only "send" appeared.
  2. probems are that emailing event is in Edit, Before Process, and there are not varibles available at this stage. So I cannot readily use the table field values in my email. A perfect place to have the email event would be Edit, After record updated. But then your codes don't work...
    Any suggestions?

J
Jane 1/21/2008

Hi,
try to use this code:

echo "<INPUT class=button type=button value=\"&nbsp;&nbsp;send email&nbsp;&nbsp;\" onclick='window.location=\"TableName_edit.php?editid1=".$_REQUEST["editid1"]."&mail=yes\"'>";


You can select all required values from database in your code:

$str = "select * from TableName where ID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

//all values are in the $data array