How to set redirect to custom page after add record event

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

How to set redirect to custom page after add record event

Post by webrelated »

I am trying to set up my mailadd.php page to redirect to custom page to process the last inserted record using the Last Insert ID which i have already declared. However i tried to set a custom page redirect below in the add.php page generated by phpmaker code but it still keeps redirecting to the mail-list.php page after a new record has been successfully inserted instead of redirecting to "process-sql.php"

BELOW IS WHAT I MODIFIED IN THE ADD PAGE

case "A": // Add new record
$this->SendEmail = TRUE; // Send email on add success
if ($this->AddRow($this->OldRecordset)) { // Add successful
if ($this->getSuccessMessage() == "")
$this->setSuccessMessage($Language->Phrase("AddSuccess")); // Set up success message
$sReturnUrl = $this->getReturnUrl();
if (ew_GetPageName($sReturnUrl) == "process-sql.php") // < ------------------ Presumed spot that requires changing
$sReturnUrl = $this->GetViewUrl(); // View paging, return to view page with keyurl directly
$this->Page_Terminate($sReturnUrl); // Clean up and return


danielc
User
Posts: 1601

Post by danielc »

Use Page_Redirecting server event to redirect after add rather than modifying the code (see Server event and Client script in help file):
if ($this->IsInsert()) {
$url = "yoururl";
}


mobhar
User
Posts: 11709

Post by mobhar »

Do not ever modify the generated code. Try to always use server event as possible, afterwards re-generate your script files. This will avoid the lose of modification in future.

For your case, simply use "Page_Redirecting" server event that belongs to the "Add" page:

// Page Redirecting event
function Page_Redirecting(&$url) {
// Example:
//$url = "your URL";
if ($this->CurrentAction == "A") {
$url = "process-sql.php";
}
}


greenfish
User
Posts: 107

Post by greenfish »

Thank you! worked for me too!


junioru83
User
Posts: 2

Post by junioru83 »

Hi,

I have a sign-up form for which I've created a view ( I can't use the registration form)

Now, I've made the view with each options and everything, only guest can see this page in the menu as sign_upadd but I also have view, list edit etc for (admin) panel.

I've tried to put this bit ofcode in the View ... > Table specific > Row_inserted >

// Row Inserted event
function Row_Inserted($rsold, &$rsnew)
{
// echo "Row Inserted";
echo"asdsadasda";
$url = "thankyou.html";
$this->setSuccessMessage("Record Inserted. The ID of the new record is " . $rsnew["ID"]);
if ($this->IsInsert()) {
$url = "yoururl";
}
}

so after the guest will fill in the signup form, and is added in the datase I can send him to a thank you .html page. I've tried to put thankyou.html in the TABLE > Redirect settings > after add thankyou.html (eventhough the only valid pages in the dropdown to choose from are add, delete, edit, list view...) this didn't worked either.

the only thing I want is to have a view, with a form on it available only to guests (I use levels) and after the new subscriber fills in the details to take him to a thank you page.

Thanks a lot!


mobhar
User
Posts: 11709

Post by mobhar »

There is no event that will trigger redirect to $url variable in "Row_Inserted" server event. That's why your own redirect code in that server event will never work.

Change this:
if ($this->IsInsert()) {
$url = "yoururl";
}

to:
$this->Page_Terminate($url);


RichEB
User
Posts: 4

Post by RichEB »

I hope this saves someone time... :-)

I was trying to get this to work... with no luck. I always got an error.

I went back to it... Something was telling me to uncheck the Modal Dialog checkbox.... I did... It works!


Post Reply