This topic is locked

Insert Button feature to update field during add page?

8/4/2010 7:04:47 PM
PHPRunner General questions
F
FunkDaddy author

Let me start off by saying that although this post may seem complicated or long, what I am trying to accomplish is rather simple. Forgive me ahead of time if I've overcomplicated my explanation below.
Here's what I am trying to accomplish by using the "Insert Button" feature in PHPRunner that is supposed to let me run javascript on the client and tell the server to do something after I click the newly created button:

  1. Click on button and javascript gets the value of a field on the page called "Category" (this is a dropdown lookup field and stores the primary key for the selected category). I tried writing some javascript code to capture the value of that field on the page and assign it to the "params" array, but I failed.
  2. The value of the "Category" field is then used in a query that runs on the server side (I need to use the "Category" value in the WHERE statement of that query). This is how I wrote my code on the "Server" tab.



global $conn;

$str = "SELECT * FROM categories_tbl WHERE CategoryID=" . $params["category"];

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

$data = db_fetch_array($rs);

$result["Cat_Price"] = $data["Category_Price"];


3. On the "Client After" tab I want to assign the value returned by the server "$result["Cat_Price"]" to another field on that same "Add" page... in this case a field called "Cat_Price".
I am lost... I searched extensively through the forums... it seems there are examples for doing similar actions when it comes to edit/view or list pages... I imagine this is easier because the values of the form already exist in the database and can be referenced easily using the $keys as shown in the online manual.
Bottom line is I need to simply press on a button (while I am in an Add new record page) that is able to look up data on another table based on a field on that add page.
Yes, I know about dependent lookup boxes and I use them extensively. In this case, dependent lookups can only perform a lookup based on a single field on the page and not multiple criteria. I ultimately it would be nice to have a dependent lookup be able to reference two or more fields instead of just one.
If anyone can point me in the right direction it would be greatly appreciated.
Thanks,
M

J
Jane 8/5/2010

Hi,
this is a bug in the Insert button option on the add page. To fix it open PHPRunner5.2/source/buttonhandler.php file, locate line 56:

else



and replace it with this one:

elseif(count($postKeys))


Then check selected value in the 'Clent before' JavaScript event of your button:

params["txt"] = document.forms.editform1.value_FieldName_1.value;



Use $params["txt"] variable in your 'Server' code:

global $conn;

$str = "SELECT * FROM categories_tbl WHERE CategoryID=" . $params["txt"];

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

$data = db_fetch_array($rs);

$result["txt"] = $data["Category_Price"];



Then return correct value and assign it in the 'Clent after' event:

document.forms.editform1.value_Cat_Price_1.value = result["txt"];
F
FunkDaddy author 8/5/2010

Beautiful. It worked.. the bug is fixed. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51644&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
I am very surprised that no one else decided to create a post about this issue... I would have thought plenty of other users would have found the need to use this ajaxian-like feature on their application.
Now I can lookup data that uses more than one field for dependency when adding new records... granted, I need to click on the newly created form button to run the action... however, i will now look into a way of using javacript to click the button for me upon a OnChange event in another form field... this way it'll act and feel like the dependent lookup fields with ajax functionality.
Thanks again for the rapid response from the Jane as always and kudos to the Xlinesoft team. Keep up the GREAT work... answering forum questions and contributing code to improve your product is one of the major reasons I chose you guys.
Best,
M

romaldus 8/5/2010



Hi,
this is a bug in the Insert button option on the add page. To fix it open PHPRunner5.2/source/buttonhandler.php file, locate line 56:

else



and replace it with this one:

elseif(count($postKeys))



there is no in line 56 :
buttonhandler.php :

<?php

include("include/dbcommon.##@ext##");

$params = (array)my_json_decode(postvalue('params'));

$buttId = $params['buttId'];
// proccess table events

##foreach @BUILDER.controlHandlers as @c filter @c.strEventID=="EVENT_BUTTON"##

##foreach @BUILDER.tables as @t filter @t.controlLinks.len##

##foreach @t.controlLinks as @h filter @h.id = @c.strName##

if($buttId=='##@c.strName##')

{

include("include/##@t.strShortTableName s##_variables.##@ext##");

include("include/##@t.strShortTableName s##_settings.##@ext##");

buttonHandler_##@c.strName##($params);

}

##endfor##

##endfor##

##endfor##
// proccess non table events

##foreach @BUILDER.controlHandlers as @c filter @c.strEventID=="EVENT_BUTTON"##

##foreach @BUILDER.controlLinks as @h filter @h.id==@c.strName##

if($buttId=='##@c.strName##')

{

buttonHandler_##@c.strName##($params);

}

##endfor##

##endfor##

// create table and non table handlers
##foreach @BUILDER.controlHandlers as @c filter @c.strEventID=="EVENT_BUTTON"##

function buttonHandler_##@c.strName##($params)

{

global $strTableName;

$result = array();

$keys = array();

// if sended array of keys

if (postvalue('keys'))

{

$postKeys = (array)my_json_decode(postvalue('keys'));



$tKeysNamesArr = GetTableKeys($strTableName);



foreach ($postKeys as $ind=>$value)

{

$keys[$ind] = array();

$recKeyArr = explode('&', $value);

for($j=0;$j<count($tKeysNamesArr);$j++)

{

$keys[$ind][$tKeysNamesArr[$j]] = $recKeyArr[$j];

}

}

}



##@c.server.strEventCode##;

echo my_json_encode($result);

}

##endfor##

?>
F
FunkDaddy author 8/5/2010

Romaldus... did you check this the installation directory of PHPRunner?
The "Else" code is indeed online 56 as Jane pointed out. You should be checking this file C:\Program Files\PHPRunner5.2\source
You may have been checking the folders on your project... although, I'm not sure such a file exists directly in the projects.
By the way... I am using PHPRunner 5.2 (Build 5482)... are you using the same version?
Best,

romaldus 8/5/2010



Romaldus... did you check this the installation directory of PHPRunner?
The "Else" code is indeed online 56 as Jane pointed out. You should be checking this file C:\Program Files\PHPRunner5.2\source
You may have been checking the folders on your project... although, I'm not sure such a file exists directly in the projects.
By the way... I am using PHPRunner 5.2 (Build 5482)... are you using the same version?
Best,


Thanks. Upgraded to PHPRUNNER latest version. It works !!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51651&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

F
FunkDaddy author 8/5/2010

Great... glad to hear it.
I plan on posting some code on the "Tips & Tricks" forums to clarify how to take full advantage of the insert button ajax calls through javascript.
The code will show how to use a button that updates the pricing of a product in an add page based on the quantity selected... this uses multiple "dependencies" and helps solve the current limitation of PHPRunner 5.2 with only one dependency allowed per lookup column (Yes, I know you can "thread" those dependencies, however they must be done one control at a time and are not able to handle true "multi dependency".
Best,

romaldus 8/6/2010



Great... glad to hear it.
I plan on posting some code on the "Tips & Tricks" forums to clarify how to take full advantage of the insert button ajax calls through javascript.
The code will show how to use a button that updates the pricing of a product in an add page based on the quantity selected... this uses multiple "dependencies" and helps solve the current limitation of PHPRunner 5.2 with only one dependency allowed per lookup column (Yes, I know you can "thread" those dependencies, however they must be done one control at a time and are not able to handle true "multi dependency".
Best,


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