This topic is locked
[SOLVED]

 Populate "Add on the fly" screen from current record

5/9/2017 2:18:25 PM
PHPRunner General questions
S
Scrolin author

I have a lookup that limits the values displayed to those relevant to another (read only) field on the edit page. This I've achieved by using the 'dropdown dependent on' function (the field depended upon is not a lookup but it seems to work).
I'd like the Add New dialogue to populate the field depended upon from the edit page. mhollibush has given a solution in this forum topic which seems to work, but throws up a new page rather than the popup produced by PHPRunner's generated link.
Does anyone know what to change in the hyperlink planted by mhollibush's solution to produce the popup?
It would also be nice to have button rather than a hyperlink to trigger the 'add new'. Advice on how to achieve that would also be welcome.
Thanks
P.S. I'm using PHPRunner 9.7

S
Scrolin author 6/4/2017

Finally managed to sort it myself. In the following, modify the bits to suit your application
As in mhollibush's solution I set the target field on the Add page to have a default value of $_GET["[color="#FF0000"]EventID"]
Then I moved to the page where the Add New button was to appear

I found not having the field depended upon as a dropdown in it's own right proved to be unreliable. So I had to add the field, define it as a dropdown, and, in HTML mode move it to its own division with the the style attribute set to display=none (in my case I didn't want this field to be displayed, if you wish to display it as read only as well I suggest you create an alias to the field for display)
<DIV style="display: none;">

{$_editcontrol}

</DIV>

[/size]

Then I added the button setting the ClientBefore function to the following
var evctrl = Runner.getControl(pageid,'[color="#FF0000"]EventID');

Runner.displayPopup({url:"="+evctrl.getValue(),

header:"[color="#FF0000"]Add New Butt Number"

});

return false; // prevent execution of "Server" and "Client After" events.

[/size]
Note the addition of NoHeader=Y to the url parameters. That is because I found that the site Header was being included in the Add page when clicking on the button despite it being a popup (might this be a bug in PHPRunner?). To inhibit the site header on this page I then defined the site header with a conditional wraparound as follows
<?php

if ($_GET["NoHeader"]!="Y") {

$rs = CustomQuery("select GETCONFIG_ChampTitle() As Title;");

$data = db_fetch_array($rs);

echo "<h1><img src=\"natlogo_small.png\" alt=\"Nationals Logo\">".$data["Title"]."</h1>";

}

?>

[/size]
One word of warning, watch the permissions on the Add Page. I had some users denied access to it without disabling the button for them. For them, clicking on the button brought up the corresponding list page instead, and god knows what would have shown if that had been denied aswell