As we have already known, PHPMaker by default will generate a "Copy" icon/inline-link/text-link in order to add a new record by copying the existing record; either from List or View page. User then will be able to quickly add a new record without having to type all the values for all fields. Let system copies from the existing record, and then user can simply change the certain field(s) only. This "Copy" functionality actually is similar to "Add". The main difference between "Add" and "Copy" is that "Copy" action can increase the productivity of user while adding new record, since users do not have to enter the values in all fields from the beginning again.
Unfortunately, for some conditions, we don't want this "Copy" functionality is available both in List and View page. We have to hide it and also disable its functionality. The main reason for this since we want to force user entering all the values with the fresh data. Moreover if we have the certain fields that act as the key, then they should not be allowed contain with the existing value from another records in the Add page.
So, this following trick will show you how to prevent "Copy" action while user is adding a new record into the database. First, we are going to hide the "Copy" inline-link from each row record in List page. Secondly, we are going to hide the "Copy" text link in View page. Thirdly, we are going to prevent user do the Copy action, even the "Copy" inline-link has been hidden from each row record. And then finally, we have to redirect user back to the normal add page.
This trick is really important, so user cannot cheat anymore by adding the certain parameter(s) from the URL of Add page.
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 10, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
[hidepost]
- Open your PHPMaker project (.pmp) file using PHPMaker application.
-
Click on your desired table/view, then click on Code (Server Events, Client Scripts and Custom Templates) tab. Expand the Server Events -> Table-Specific -> List Page, and then click on ListOptions_Rendered item/function. In the right pane, just insert the following code into the function:
$this->ListOptions->Items["copy"]->Visible = FALSE; // Hide the Copy inline-link/icon in List page
-
Still in the Server Events, expand the following: Server Events -> Table-Specific -> Common, and then click on the Row_Rendered item/function. In the right pane, just insert the following code into the function:
$this->CopyUrl = ""; // Do not allow user to copy record from View page!
This code will hide the "Copy" text link from the View page.
-
Still in the Server Events, expand the following: Server Events -> Table-Specific -> Add/Copy Page, and then click on the Page_Load item/function. In the right pane, just insert the following code into the function:
if (@$_GET["theparameter"] != "") { // Warning: You have to adjust "theparameter" with yours! $this->setFailureMessage("Sorry, data cannot be copied."); $this->Page_Terminate("yourtableorviewadd.php"); // Warning: You have to adjust "yourtableorviewadd.php" with your related normal add page }Now let's discuss the code in this step. In the first line of the code, you can see that "theparameter" is the parameter that derived from GET method in the URL. You have to adjust "theparameter" with your real parameter name. In the third line of the code, you can see "yourtableorviewadd.php" is the normal add page. In other words, the Copy action can be performed by typing "yourtableorviewadd.php?theparameter=123" (for example, we want to copy from the record which contains the ID as "123"). Also, you have to adjust "yourtableorviewadd.php" with your add page, so user will be redirected back to the normal add page afterwards.
In conclusion, the code in this step will prevent user to perform Copy action by typing the URL directly. Hiding the "Copy" inline-link/icon cannot just solve the problem. That's why you have to handle it also from the Page_Load function in Add/Copy page from Server Events.
- Re-generate your script files using PHPMaker, as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.