Contents

 
Home
PHPRunner 6.0 manual
Prev Page Next Page
 
 

Insert button

 

To add the button to a web page, follow the instructions below.

1. Proceed to the Visual Editor and select a page you wish to modify.
2. Right click somewhere on the page, select Insert -> Button.
3. Type in the button caption and code to be executed after button is pressed. You can add both client-side (Javascript) and server-side (PHP) events. Click OK.

insert_button_code

4. Now button is added to your web page. You can drag the button to change its location.

insert_button_res

To edit the code, right click the button and select Properties. Also you can edit the code on the Events page.

Example 1. Insert "Add this product to shopping cart" button

For the Edit/View pages the $keys parameter in the OnServer event contains the information about the current record. To access specific key column you can use $keys["KeyFieldName"].

For example, there is a Products table. To insert Add this product to shopping cart button on the View page, add the following code to the OnServer event (Server tab):

global $dal;

if ($keys["ProductID"])

{

//add new records to the ShoppingCart table

//save current username in the UserID field

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

$ShoppingCart->Product = $keys["ProductID"];

$ShoppingCart->Quantity = 1;

$ShoppingCart->UserID = $_SESSION["UserID"];

$ShoppingCart->Add();

}

$result["txt"] = "Product was added";

and this code to the OnAfter event (Client After tab):

var message = result["txt"] + ".";

For more information about using Data Access Layer (DAL), see Data Access Layer.

Example 2. Send records selected on the List page via email

For the List page the $keys parameter in the OnServer event contains the information about all records that are selected on this page:

$keys[0][ "ID1"], $keys[0]["ID2"] - first selected record

$keys[1][ "ID1"], $keys[1]["ID2"] - second selected record

...

To send records selected on the List page via email, add the following code to the OnServer event (Server tab):

global $dal;

$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("TableName");

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

$datatmp = db_fetch_array($rstmp);

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

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

$email_msg.= "\r\n";

}

//send email

$email="test@test.com";

$subject="Sample subject";

runner_mail(array('to' => $email'subject' => $subject,

  'body' => $email_msg));

For more information about using Data Access Layer (DAL), see Data Access Layer.

Example 3. Modify the value of a field for all selected records on the List page

To modify the value of a field for all selected records on the List page, add the following code to the OnServer event (Server tab):

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

{

$sql = "update Invoices set Status='Paid' where InvoiceID=" .$val["InvoiceID"];

CustomQuery($sql);

}

Example 4. Make a button redirect to another page

To make a button redirect to another page, add the following code to the OnBefore event (Client Before tab) or OnAfter event (Client After tab):

location.href="http://cnn.com";

Example 5. Show the message to the customer for limited period of time

Let's say you have a button that retrieves a piece of sensitive info from the server that needs to be shown to the customer for a short period of time. After that this message needs to be hidden. To do this, add the following code to the OnAfter event (Client After tab):

// this message includes the SSN retrieved from the server

var message = result["txt"];

ctrl.setMessage(message);

 

// clear the message after 5 seconds

setTimeout(function(ctrl) {

 ctrl.setMessage("");

}

, 5000, ctrl);

Converted from CHM to HTML with chm2web Standard 2.85 (unicode)