This topic is locked

Send LIST PAGE as email

3/6/2007 8:27:52 AM
PHPRunner General questions
L
Lisa2006 author

Hi Everyone,
Can you please help me again.
I have the following created for test purposes:
Table: _demotable

field: username

field: password

field: firstname

field: surname

field created by PHPrunner: ID
User initially registers there 'username', 'password' & 'email address'

User then logs In.

User then selects the 'Edit' page and enters there 'Firstname' & 'Surname' - followed by 'SAVE'
upon saving the record,
I want the built-in 'LIST PAGE' to be emailed back to me.
So far I have carried out the following:
Events (step12) > Table Events > Before Record Updated > Send Email With New Data
function BeforeEdit(&$values, $where)

{
// Parameters:

// $values - Array object.

// Each field on the Edit form represented as 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited
//****
Send email with new data ****
$email="lisa@myemailprovider.co.uk";

$message="";

$subject="Thank you for your response";

$confEmailHeader = "From: lisa@myemailprovider.co.uk\n";
// foreach($values as $field=>$value)

// $message.= $field." : ".$value."\r\n";
$label = "First Name Entered";

$message.=$label.": ".$values["firstname"]."\r\n";
$label = "Surname Entered";

$message.=$label.": ".$values["Surname"]."\r\n";
mail($email, $subject, $message, $confEmailHeader);
return true;
// return true if you like to proceed with editing this record

// return false in other case
}
This works fine!!!

However, when i get onto the main project I will have many fields to be emailed back to me. It would be much easier to have the 'LIST PAGE' emailed.
Please HELP!!!
Thanks in advance

Lisa

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4755&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />

J
Jane 3/6/2007

Lisa,
you can do the following:

  1. proceed to the "Visual Editor" tab
  2. turn on "HTML mode", find this line:
    <!-- delete form -->

and add following code just before:

<A onclick="if (!confirm('Do you really want to update these records?')) return false; frmAdmin.a.value='update'; frmAdmin.submit(); return false;"

href="TableName_list.htm#">send email</A>


3. proceed to the Events tab and add BeforeDelete event.

Here is a sample code:

function BeforeDelete($where)

{

//delete records

if(@$_POST["a"]=="delete")

return true;
//send email with selected records

global $conn,$strTableName;

$email="test@test.com";

$message="";

$subject="your subject";

$rs = db_query("select * from " . $strTableName ." where ". $where,$conn);
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

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

mail($email, $subject, $message);

}

return false;

}

L
Lisa2006 author 3/6/2007

Hi Jane,
Have carried out the following but NO EMAIL or Confirmation to Update record.
Have carried out the following:
"Visual Editor" tab > "LIST PAGE" > HTML Mode >
Above <!-- delete form --> entered
<A onclick="if (!confirm('Do you really want to update these records?')) return false; frmAdmin.a.value='update'; frmAdmin.submit(); return false;"

href="_demotable_list.htm#">send email</A>
Events tab > "LIST PAGE" > "Before Record Deleted" >
function BeforeDelete($where)

{

//delete records

if(@$_POST["a"]=="delete")

return true;
//send email with selected records

global $conn,$str_test;

$email="lisa@myemailprovider.com";

$message="";

$subject="Thank you";

$rs = db_query("select * from " . $str_demotable ." where ". $where,$conn);
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

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

mail($email, $subject, $message);

}

return false;
Please can you help

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=16043&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

J
Jane 3/7/2007

Lisa,
you don't need to replace $strTableName with your value. $strTableName is the global variable which contains name of the current table.

Here is the correct event code:

function BeforeDelete($where)

{

//delete records

if(@$_POST["a"]=="delete")

return true;
//send email with selected records

global $conn,$strTableName;

$email="lisa@myemailprovider.com";

$message="";

$subject="Thank you";

$rs = db_query("select * from " . $strTableName ." where ". $where,$conn);
if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

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

mail($email, $subject, $message);

}

return false;

}

L
Lisa2006 author 3/7/2007

Hi Jane,
Thanks for yuor reply.
I have amended the code snippet in the Events > List Page > Before Record Deleted
But still no joy...... Not getting email.
Can you please advise if this code snippet is in the right Event location.

[I have removed the original code snippet in this posting from Events (step12) > Table Events > Before Record Updated > Send Email With New Data)]
New query:

From my initial enquiry, where the following code worked o.k

Events (step12) > Table Events > Before Record Updated > Send Email With New Data
function BeforeEdit(&$values, $where)

{
// Parameters:

// $values - Array object.

// Each field on the Edit form represented as 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited
//** Send email with new data ****
$email="lisa@myemailprovider.co.uk";

$message="";

$subject="Thank you for your response";

$confEmailHeader = "From: lisa@myemailprovider.co.uk\n";
// foreach($values as $field=>$value)

// $message.= $field." : ".$value."\r\n";
$label = "First Name Entered";

$message.=$label.": ".$values["firstname"]."\r\n";
$label = "Surname Entered";

$message.=$label.": ".$values["Surname"]."\r\n";
mail($email, $subject, $message, $confEmailHeader);
return true;
// return true if you like to proceed with editing this record

// return false in other case
}
I have only just noticed the following.

J
Jane 3/7/2007

Lisa,
this code works fine on my test box.

Please publish your project on Demo Account and post link to your pages here or send to support@xlinesoft.com.

I'll find what's wrong with your project inspecting it at Demo account site.
Regarding the second question.

If username and email aren't on the Edit page you need to select these values from the database and then use it in your code.

You can find some sample events in the PHPRunner Help.