User defined buttons

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
janosh
User
Posts: 7

User defined buttons

Post by janosh »

Hi there,
Is it possible with PHPMaker 10 to define my own buttons underneath the table, which execute a server side script when clicked?
regards,
janosh


mobhar
User
Posts: 11660

Post by mobhar »

Yes, it is. But you cannot run the server event on its click event. You should run the Javascript code on the click event.

Put this following code into your "Page_Render" server event of the List page in order to insert the new button:

$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$item->Body = "<a class=\"ewAction\" href=\"\" onclick=\"YourJavaScritpFunction();return false;\">My New Button</a>";

However, if you want to execute your own php code in the certain php file, try to change the last line of that code above, become:

$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php\" >My New Button</a>";


starquest321
User
Posts: 140

Post by starquest321 »

Can you gave an idea of what this would be used for so I can enhance my own project? What are you doing with your own buttons server side for example?


janosh
User
Posts: 7

Post by janosh »

Hi starquest321,
In my case I use that button for "Approval". After the user has reviewd all relevant records in the list page, s/he can click on [Approve] button and then a flag gets set on server side for every selected record.
brgds,
janosh


sentnel
User
Posts: 9

Post by sentnel »

Hello again!

My problem is constructing the URL, referencing the variable.

This:
$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php?\" >My New Button</a>";

How do I end up with a URL like this:
yourphpfile.php?purchaseorder=800

If I try someting like this
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=$ordernumber">Print Purchase Order</a>";

I get a blank page. Thanks for your help!


mobhar
User
Posts: 11660

Post by mobhar »

@sentnel,

You have to handle the receiving variable in your "printordencompra.php" file by using $_GET["purchaseorder"] variable.

For example, in your "printordencompra.php" file, make sure you have already had the following code before processing the value:
<?php
$mypurchaseorder = "";
if (isset($GET["purchaseorder"])) {
$mypurchaseorder = $
GET["purchaseorder"];
} else {
$mypurchaseorder = "No purchase order provided";
}
echo $mypurchaseorder; // just to make sure the value is right
?>

Also, make sure you have already had a correct value in $ordernumber variable before clicking on that custom link.


sentnel
User
Posts: 9

Post by sentnel »

Thanks mobhar!

I have no problem receiving the variable, the problem is "sending" the variable. My problem is here:

$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php?\" >My New Button</a>";

How do I properly format this to include and send the "purchaseorder" variable after "yourphpfile.php?\"?

Thanks again!


mobhar
User
Posts: 11660

Post by mobhar »

Try this:

$ordernumber = "800"; // make sure the order number is correct
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "">Print Purchase Order</a>";


sentnel
User
Posts: 9

Post by sentnel »

Didn't work.

Also tried:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "">Print Purchase Order</a>";

and:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder= $ordernumber">Print Purchase Order</a>";

The application won't even load, just get a blank screen. :-(


mobhar
User
Posts: 11660

Post by mobhar »

In which server event did you put the code?


danielc
User
Posts: 1601

Post by danielc »

sentnel wrote:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder="
. $ordernumber . "">Print Purchase Order</a>";

Miss \ for your " after $ordernumber:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "\">Print Purchase Order</a>";


sentnel
User
Posts: 9

Post by sentnel »

Thanks a lot to all!

For future reference this the complete solution:

Code into your "Page_Render" server event of the List page:

$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");    
$ordernumber=$this->ordenCompraDetail->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?orden_compra=" . $ordernumber . "\">Print Purchase Order</a>";

Thanks again to all!


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi,
i'm sorry. I tried to use your suggestion but i don't understand how pass orderId value.

Can someone help me?

This is my code in ListPage --> Page Render:

if (!isset($_GET["showdetail"])) {
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$ordineFattura = $this->OrderID->CurrentValue;
//$item->Body = "<a class=btn href=Fattura.php?StampaOrdine=OrdersMaster&fk_OrderId=" .$ordineFattura. ">Stampa Fattura</a>";
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?orden_compra=" . $ordineFattura . "\">Print Purchase Order</a>";
}
}

Thank you.
Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Fakiro82 wrote:
i don't understand how pass orderId value.

You need to put your code in "Page_Render" of "List Page" that belongs to your detail table (not in master table).


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi mobhar,
My code is in OrderDetails Table (Detail Table). My Master Table is Orders table, but I don't know how can i do to pass value OrderID.
Probably my error is here:

$ordineFattura = $this->OrderID->CurrentValue;

because OrderId-->CurrentValue is empty. Right? Can you help me?

Thank you so much for your all suggestion.

Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Make sure you have already open the Master/Detail List page in order to pass the OrderID value, the URL should be like this (assume you are using the demo project), for example:

orderdetailslist.php?showmaster=orders&fk_OrderID=11076

So, to make sure the button will be shown up only when the Master/Detail List page is displayed (not in the individual detail List page), then change your code become:

if ($this->getCurrentMasterTable() != "") { // make sure the detail list page is being displayed when it contains the master table (Master/Detail List page)
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$ordineFattura = $this->OrderID->CurrentValue;
//$item->Body = "<a class=btn href=Fattura.php?StampaOrdine=OrdersMaster&fk_OrderId=" .$ordineFattura. ">Stampa Fattura</a>";
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?orden_compra=" . $ordineFattura . "\">Print Purchase Order</a>";
}


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi mobhar,
first of all thank you so much.
Then, I tried with your suggest and I rewrited the code like below:

// Page Render event
function Page_Render() {
//echo "Page Render";

if ($this->getCurrentMasterTable() != "") { // make sure the detail list page is being displayed when it contains the master table (Master/Detail List page)
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton"); 
//$ordineFattura = $this->OrderID->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".urlencode($this->OrderId->CurrentValue)."\">Genera Fattura</a>";

}
}

The script works only If I add ".urlencode($this->OrderId->CurrentValue)." in URL. but If I insert ".$ordineFattura." in URL it doesn't work ($ordineFattura is always empty and I didn't find the problem). I don't know if this ( ".urlencode($this->OrderId->CurrentValue).") is the right way to solve the problem but it works. I would like to make it work like you suggest me.

Thank you so much mobhar.

Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Change:
//$ordineFattura = $this->OrderID->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".urlencode($this->OrderId->CurrentValue)."\">Genera Fattura</a>";

to:
$ordineFattura = urlencode($this->OrderID->CurrentValue);
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".$ordineFattura."\">Genera Fattura</a>";


mobhar
User
Posts: 11660

Post by mobhar »

Sorry, this code:
$ordineFattura = urlencode($this->OrderID->CurrentValue);

should be:
$ordineFattura = urlencode($this->OrderId->CurrentValue); // case-sensitive field name


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi mobhar,
Now it's works.

Thank you so much.

Andrea.


Post Reply