This topic is locked

Cool "smart" checkbox feature - Client Before, On Server, Clie

6/29/2011 2:52:52 PM
PHPRunner Tips and Tricks
F
FunkDaddy author

If you want to create a checkbox that has the same functionality as the "insert button" features available in PHPR via the visual editor you can simply take the following steps:
Step 1:

Insert a button in desired location of your page (not the HTML button, instead make sure you use the PHPR "insert button" located in same menu as "insert php snippet" (I really wish Sergey would give the insert button a more descriptive name such as "insert action button").
Step 2:

In visual editor, switch to HTML view and modify the newly created button as follows:



<INPUT id=checkbox_button_test class=button type=checkbox typeid="ib">

<LABEL for=checkbox_button_test>Check this box to blah, blah, blah...</LABEL>



//Notice we changed the button type to "checkbox", gave it a descriptive id name, and deleted tha value attribute.

//When you tack on a label to a checkbox it allows it to be checked/unchecked even when user clicks on the label's text (so they don't have to use pinpoint accuracy in checking the box_).
Step 3:

In the events tab find the button event that was created (Client Before, Server, Client After) and insert the following code:


//Client Before ------------------------------

this.setEnabled(); //ensure once checked it can be checked again and again several times without page refresh
//Set a value for params["checkbox_button_test"] as 1

if(document.getElementById("checkbox_button_test").checked == true){

params["checkbox_button_test"] = 1;

//alert("Checked val: "+params["checkbox_button_test"]); //UNCOMMENT FOR TESTING

}
//Set a value for params["checkbox_button_test"] as 0

if(document.getElementById("checkbox_button_test").checked == false){

params["checkbox_button_test"] = 0;

//alert("Unchecked val: "+params["checkbox_button_test"]); //UNCOMMENT FOR TESTING

}
//Server ---------------------

//Run whatever php commands you need to execute. What I've included here is merely a sample action to update the status of a wizard tab step.

global $conn;
if($params["checkbox_button_test"] == 1){

$strUpdate =

"

UPDATE

parent_confirmation_orders_tbl

SET

Instructions_Tab = 1

WHERE

LinkUserID = ".$_SESSION["User_ID"];

CustomQuery($strUpdate);

} else {

$strUpdate =

"

UPDATE

parent_confirmation_orders_tbl

SET

Instructions_Tab = 0

WHERE

LinkUserID = ".$_SESSION["User_ID"];

CustomQuery($strUpdate);

}
//Client After -----------------

//Lets leave the checkbox checked or unchked, otherwise we lose value due to default ajax refresh here.

if(document.getElementById("checkbox_button_test").checked == true){document.getElementById("checkbox_button_test").checked = true;}

if(document.getElementById("checkbox_button_test").checked == false){document.getElementById("checkbox_button_test").checked = false;}

window.location.reload();


That's it. Enjoy.

G
giwi_dev 12/12/2011

Many thanks for this tip, i needed to add checkboxes in another scenario and this helped me getting them there

L
laonian 12/24/2011

[b]FunkDaddy,

[/size]
[/b]

[b]
[font="Arial"][size="2"]this is the original button code

[/size]

[b]
When I change it (replacing the "[color="#0000FF"]<A>......</A>" section), my code looks like:

[/size][/b]

**


**

[b]**

[/b]

W
wildwally 2/9/2012



[b]FunkDaddy,

[/size]
[/b]

[b]
[font="Arial"][size="2"]this is the original button code

[/size]

[b]
When I change it (replacing the "[color="#0000ff"]<A>......</A>" section), my code looks like:

[/size][/b]

**

[b]****

[/b]


Try replacing it all (Original Text) I was able to get it to work by doing so, excellent tip. Thanks

K
kadidarm 7/6/2012

I dont think this works on phprunner 6.1 anymore