Conditional hide ADD button according to master table row

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Plorenzo9
User
Posts: 17

Conditional hide ADD button according to master table row

Post by Plorenzo9 »

Hi, I need to hide the button to add, according to the value of a field of its master table. How I can achieve this? all I saw in the forum I have not worked.
I'm using v10 PHPMaker. Any help is welcome. Thank you!


danielc
User
Posts: 1601

Post by danielc »

Add your code in Page_Render server event for your detail list page:
if (your condition)
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE; // to hide detail add link


Plorenzo9
User
Posts: 17

Post by Plorenzo9 »

TKS Daniels! I have just one question, how can i get a field value in this event (Page_Render)? I have to check one Field [Estado] and if it its biggers than one, i cant add in the child database.


danielc
User
Posts: 1601

Post by danielc »

You can get a field value by:
ew_ExecuteScalar("SELECT YourField FROM YourTable WHERE id = xxx");


Plorenzo9
User
Posts: 17

Post by Plorenzo9 »

Hi Danielc, First, thanks for your help. I tested what you tellme and didnt work. i found function setCanAdd(), this can be used in Page Load event, but quit the button ADD. Now, i want run this, according a field value from master table, wich its State. Do you know how can i get this value in the list page, to evaluate this in PageLoad Event and run or not the funcition SetCanAdd??

TKS, Again.-


danielc
User
Posts: 1601

Post by danielc »

Could you tell me what is the error after you added the code? Or post your code in detail.

To get value from master table in Page_Load server event, need to execute this code:
ew_ExecuteScalar("SELECT YourField FROM YourMasterTable WHERE xxx");


Plorenzo9
User
Posts: 17

Post by Plorenzo9 »

Finnally, this works, maybe there are better options, but this work for me:

function Page_Load() {
//echo "Page Load";
//Desabilita agregar si el Estado es distinto a BORRADOR.
$idForm = @$GET["id"];
if (!is_null($idForm)){
$
SESSION['id']=$idForm;
$estado = ew_ExecuteScalar("select estado from solicitudes where id='".$idForm."';");
if ($estado == 1) {
Security()->setCanAdd(TRUE);
}else{
Security()->setCanAdd(FALSE);
}
}else{
$estado = ew_ExecuteScalar("select estado from solicitudes where id='".$_SESSION['id']."';");
if ($estado == 1) {
Security()->setCanAdd(TRUE);
}else{
Security()->setCanAdd(FALSE);
}
}
} //event End


Post Reply