This topic is locked

Adding A New Button To Add/edit Pages

7/11/2013 11:34:57 AM
PHPRunner Tips and Tricks
Sergey Kornilov admin

Lets say we need to add a new button that will save the record and redirect user back to the List page.

  1. Add a new button to the Add or Edit page via 'Insert button' function in Visual Editor
  2. ClientBefore event:

pageObj.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

formObj.baseParams['golist'] = "1";

});
$("#saveButton1").click();
return false;


3. AfterAdd or AfterEdit event:

if($_REQUEST["golist"])

{

header("Location: ..._list.php");

exit();

}
P
paulirvine 3/19/2014

Hi Sergey - this "kinda" works... but only in the simple sense. If your ADD page is within a standard LIST page, and you can name the LIST page, yes it works. But as often happens, the ADD page is also presented as a child page ... and going back to a hard coded LIST parent is not appropriate.

e.g., Employer has Divisions. In Employer, click to see Divisions for Employer. In Divisions for Employer, click ADD division. Using this code we dont know whether we are in add Divisions or add Divisions for an employer. So if you go to divisions_list.php, i.e., your button code is naming the target page, then it can often go to the wrong page. What is needed is an option to "ADD and STAY in ADD mode" or "ADD and return to where CAME FROM". Those are the only two options that anyone could require.
paul

Sergey Kornilov admin 3/19/2014

Using the same page as a child page and as a standalone page is usually a bad idea - you can easily lose data integrity. If you must do that there are still two workarounds:

  • create a custom view for this child page to use in standalone mode
  • or use a session variable to keep track of the current add mode (standalone or child mode). You can set this variable while accessing master list page or standalone list page. Based on that session variable value you can perform conditional redirect.