This topic is locked

Adding an additional button to the Edit page

1/27/2009 9:44:27 AM
PHPRunner Tips and Tricks
J
Jane author

Let's say you want to add a Save and back to list button on the Edit page which should take you back to the list page after record is saved.
Here is how this can be done:
[size="4"]PHPRunner 5.0-5.2:[/size]

  1. In Visual Editor create a copy of the Save button

    Switch to HTML mode and modify new button label and ID
    <INPUT class=button id=submit2 type=submit value="Save and back to list" name=submit2>


2. Implement AfterEdit event:

if ($_REQUEST["submit2"]=="Save and back to list")

{

header("Location: cars_list.php");

exit();

}


[size="4"]PHPRunner 5.3-6.x:[/size]

  1. In Visual Editor create a copy of the Save button

    Switch to HTML mode and modify new button label and ID
    <INPUT class=button id=submit2 type=button value="Save and back to list" name=submit2>


2. process this button in the JavaScript onload eventon the Eventstab:



$("#submit2").bind("click", {page: this}, function(e){

var page = e.data.page;

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

formObj.baseParams['submit2'] = 'Save and back to list';

}, page, {single: true});

page.on('afterSave', function(respObj, formObj, fieldControlsArr, pageObj){

delete formObj.baseParams['submit2'];

}, page, {single: true});

page.saveHn(e);

});


3. Implement AfterEdit event:

if ($_REQUEST["submit2"]=="Save and back to list")

{

header("Location: cars_list.php");

exit();

}


[size="4"]PHPRunner 7.x-8.x[/size]

  1. In Visual Editor add a new button to the Edit page.
  2. In Button's Server event use the following code:

$_SESSION["redirect"]=true;


3. In Button's ClientAfter event imitate a click of the main Save button

$("#saveButton1").click();


4. AfterEdit event. Check $_SESSION["redirect"] variable and perform a redirect to the list page if value is true.

if ($_SESSION["redirect"]==true) {

$_SESSION["redirect"]=false;

header("Location: cars_list.php");

exit();

}
S
s.kahya 2/19/2009

Dear Jane
I tried to do whatever you explained but somehow it did not work. I would like to know if there is a typing mistake. I am not sure but it might be a problem

below.
if($_REQUEST["submit2")=="Save and back to list")
Could you please check one more time and inform me why I cannot do it right.

Also I do not understand where is AFTEREDIT you mentioned. I wonder if we have to create it or we have it already. Because I cannot fınd it on the EDIT PAGE.
Thanks much!
Selcuk

admin 2/19/2009

All events, including AfterEdit can be found on Events page in PHPRunner.

S
s.kahya 2/19/2009

Dear admin
sorry

this is code not working <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=38050&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

please help
error description

Parse error: parse error in c:\apache\htdocs\cars2\output\include\carsadmin_cars_events.php on line 4
afteredit event codes
<?php

function AfterEdit(&$values, $where, &$oldvalues, &$keys,$inline)

{

if ($_REQUEST["submit2")==("Save and back to list")

{

header("Location: carsadmin_cars_list.php");

exit();

}

}

?>

admin 2/20/2009

Try this:

if ($_REQUEST["submit2"]=="Save and back to list")

{

header("Location: carsadmin_cars_list.php");

exit();

}
S
s.kahya 2/20/2009

Dear admin
code is working now .
thanks much.
best regards

hfg 3/9/2009

I'm glad to have found this trick. It takes care of the problem with inline edits and the afteredit redirect.
Question for verision 5.1 which has the navigation (forward and back) buttons.
Would it be possible to write a code for "Save and Next Record"?
Thanks

J
Jane author 11/25/2010

Hi,
yes it's possible.

Just select record with next ID in your After record added event on the Eventstab and redirect to the edit page of this record.

F
FunkDaddy 6/6/2011

Potential issue with this tip....
Jane,
I implemented the example you gave us on this page and it works just fine. However, it does not work if you attempt to use the newly created submit button when form field validation fails. For example, if you have a form that has 3 required fields, but the user only completes 2 fields, then later fills out the 3rd field (after being prompted by form that field is required) the newly created button no longer works.
So it seems like this code is missing something that allows this submit button to be clicked on more than once (until form fields are fully validated with javascript).
Does anyone have a solution to this issue? I tried adding this line to the example Jane gave in this post but it didn't work: this.setEnabled();
Cheers,

F
FunkDaddy 6/6/2011

A simpler approach to having a submit button thank you message and redirect after submit.
Due to the issue I reported (see my previous post in this thread), whereby the submit2 button doesn't submit form if any field validation fails after attempting first submit, I came up with a solution that worked for me.
I simply added this code to the "After Record Added" page"


echo "

<script type=\"text/javascript\">

alert('Thank you for submitting your request.\\nYour department admin will now review your information.');

window.location=\"login.php\";

</script>";


That's all. Now I can use the default "Save" button on my add form, display a thank you message, and redirect user to another page after successfully validating and submitting all fields on the form!
Best,

F
FunkDaddy 6/8/2011

Quick update... the example I gave above will only work if your edit window is not displayed in pop-up mode!
Cheers,

D
droogers 12/3/2011

How does the code work in phprunner 6.0 ?

L
laonian 12/21/2011

I want to add a similar button on the Edit/Add page with PHPRunner 6.0. Tried the method for PHPRunner 5.0 and it did not work.
Could the support or anybody give an update on this thread for PHPRunner 6.0? Thanks.

T
Tricause 1/13/2012



I want to add a similar button on the Edit/Add page with PHPRunner 6.0. Tried the method for PHPRunner 5.0 and it did not work.
Could the support or anybody give an update on this thread for PHPRunner 6.0? Thanks.



I've tested and implemented the code above on PHPRunner 6.0, so it should still work.
You can streamline the attach process if there are multiple multiple buttons for which you want to attach the save event to:



function assignProperties(buttonName, buttonCaption, scope) {



$("#" + buttonName).bind("click", {page: scope}, function(event) {



var page = event.data.page;

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

formObj.baseParams[buttonName] = buttonCaption;

}, page, {single: true});

page.on('afterSave', function(respObj, formObj, fieldControlsArr, pageObj){

delete formObj.baseParams[buttonName];

}, page, {single: true});

page.saveHn(event);

});



} // end assignPropertiesCategory
...
assignProperties("submitNext", "Next");


Further, the example given by Jane does not incorporate validation techniques. For example, pressing this button but having the form validation fail will still save this button to the $_REQUEST variable. To remedy this, you could use the following:



...

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

var form = this.getForm();

// exits if fails validation used by PHPRunner

if (!form.validate())

return false;

formObj.baseParams['buttonName'] = 'buttonCaption';

}

...
ncreveld 3/19/2012

Is this working in PhpRunner 6.1 build 10813 ?

I tried the code, it made a nice button but the save is not working please advice. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=65006&image=1&table=forumreplies' class='bbc_emoticon' alt=':angry:' />

Nico