Setting URL with Page_Redirecting event

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

Setting URL with Page_Redirecting event

Post by WABez »

So I have tested "Page_Redirecting" with a couple of scenarios, and discovered that the "Page_Redirecting event" is not working as I expected:

  1. No "Page_Redirecting" event configured, but "Table > Page Return" setup as "View Page"

    -> this is working like a charm, i.e. no problem!

  2. No "Page_Redirecting" event configured, but "Table > Page Return" setup as "mypageadd.php?showmaster=user&fk_user_id=" . urlencode($this->user_id->CurrentValue) . "&fk_other_param_id=" . urlencode($this->other_param_id->CurrentValue)

    -> this is also working like a charm, i.e. no problem and the confirmation page is displayed, next
    -> the URL is: h t t p : / / localhost/test/mypageadd.php?showmaster=user&fk_user_id=123&fk_other_param_id=2 (i.e. THE ID VALUES ARE CORRECT)
    -> and the record is inserted into the user table (i.e. the master table)

3 (a). "Table > Page Return" setup as "View Page", and "Page_Redirecting" event configured as: $url = "mypageadd.php?showmaster=user&fk_user_id=" . urlencode($this->user_id->CurrentValue) . "&fk_other_param_id=" . urlencode($this->other_param_id->CurrentValue);

3 (b). "Table > Page Return" empty (not setup), and "Page_Redirecting" event configured as: $url = "mypageadd.php?showmaster=user&fk_user_id=" . urlencode($this->user_id->CurrentValue) . "&fk_other_param_id=" . urlencode($this->other_param_id->CurrentValue);

-> PROBLEM, it now jumps directly to the detail page when trying to add to the master record (bypassing the master add page),
-> i.e. jumps directly to: mypageadd.php and no "ID" values in the URL,
-> it does not even go the the master page/table first to add a record in the master table, and the
-> the URL is: h t t p : / / localhost/test/mypageadd.php?showmaster=user&fk_user_id=&fk_other_param_id= (i.e. NO ID VALUES)
-> and therefore no record can be added to the user table (i.e. master table) as it is bypassed...

  1. As per 3 (a) and (b) above, but now with "Page_Redirecting" event configured as (based on what the user select in the master input record):

case ($this->myField->CurrentValue) {
switch:
case 1:
$url = "mypageONEadd.php?showmaster=user&fk_user_id=" . urlencode($this->user_id->CurrentValue) . "&fk_other_param_id=" . urlencode($this->other_param_id->CurrentValue);
break;
case 2:
$url = "mypageTWOadd.php?showmaster=user&fk_user_id=" . urlencode($this->user_id->CurrentValue) . "&fk_other_param_id=" . urlencode($this->other_param_id->CurrentValue);
break;
}

-> PROBLEM, in this scenario it does go to the add master record "add" page, but not showing the confirmation page (when submitting),
-> i.e. bypassing the confirmation page and jumps directly to: mypageadd.php (or in this case mypageONEadd.php for example)........,
-> therefore also not inserting the record into the user table (i.e. master table), and
-> the URL is: h t t p : / / localhost/test/mypageadd.php?showmaster=user&fk_user_id=&fk_other_param_id=2 (i.e. NO "FK_USER_ID" VALUE, othe_param value is good),
-> Due to incorrect values passed in the URL (and the fact that no master record is inserted), the detail record fails as well.

NOTE: the user select option with the switch works fine, but the URL parameters/values fail.


Webmaster
User
Posts: 9425

Post by Webmaster »

Note that:

  1. There is no correlation between Return Page and Page_Redirecting server event. When you use Page_Redirecting to set the URL, it overwrites the Return Page URL.
  2. If you use Page_Redirecting server event to redirect after inserting a record, and the table has autoinc field, there is value in $this-><AutoIncField>->CurrentValue, but there are no values in $this-><OtherField>->CurrentValue. The data saved is in the DbValue property.
  3. If there is no value in $this-><AutoIncField>->CurrentValue/DbValue, the record may not be inserted successfully, you can check if ($this->getSuccessMessage() <> "") to make sure there is success message first. You can also use $this->getFailureMessage() to check the error message.

WABez
User
Posts: 199

Post by WABez »

Thank you, I will go and test accordingly.

Webmaster wrote:

  • Happy with your point 1 (and noted)
  1. If you use Page_Redirecting server event to redirect after inserting a record, and the table has autoinc field, there is value in
    $this-><AutoIncField>->CurrentValue, but there are no values in $this-><OtherField>->CurrentValue. The data saved is in the DbValue
    property.

The table has an autoinc field for $this-><AutoIncField>->CurrentValue, and for $this-><OtherField>->CurrentValue is a value set in the form (user selected before the form is submitted).
I have assumed that Page_Redirecting server event is by default used to redirect AFTER inserting a record. Am I wrong in my assumption?

  1. If there is no value in $this-><AutoIncField>->CurrentValue/DbValue, the record may not be inserted successfully, you can check if
    ($this->getSuccessMessage() <> "") to make sure there is success message first. You can also use $this->getFailureMessage() to check the error
    message.

I will try this as described in point 3 above.

How do I ensure that the "Page_Redirecting" event is called after the master record is inserted successfully?


arbei
User
Posts: 9284

Post by arbei »

How do I ensure that the "Page_Redirecting" event is called after the master record is inserted successfully?

In Row_Inserted Server Event, use $this->getCurrentDetailTable() function as the condition to check is it Master/Detail Add, then call Page_Terminate by your code.

For example:
If ($this->getCurrentDetailTable() <> "") {
Page_Terminate("<URL>");
}


WABez
User
Posts: 199

Post by WABez »

Thank you, got it solved, finally!

I followed the advice from this topic: http://www.hkvforums.com/viewtopic.php?p=100816


Post Reply