redirect after new record fails

Status
Not open for further replies.

susannanam

Member
hi all,

after filling in the form and saving the record, i would like to redirect to the just saved record so that the user can see its created student number. sounds easy and i found a lot of info but i cant get it right. i tried the redirect plugin and the php pluging (at the end of form submission).

the problem might be that the pk is not int and autoincrement but a string (automatically built by php when saving and writing back onto the form). that all works perfectly fine, the record is saved correctly in the database.

i have tried e.g. the following without success:
redirect:
index.php?option=com_fabrik&view=form&formid=59&rowid={rowid}
----
redirect:
index.php?option=com_fabrik&view=form&formid=59&sh2m8_student___student_id={sh2m8_student___student_id}
----
php:
$student_id = JRequest::getVar('sh2m8_student___student_id');
global $mainframe;
$mainframe->redirect('index.php?option=com_fabrik&view=form&rowid=".$student_id');

what would the correct syntax be to redirect to the record please? thanks for anyhelp :)
 
Confirmed:
in case of a non-integer PK a redirect to
&rowid={rowid} or &rowid={table___id_raw} is working if editing an existing record (e.g. redirecting to &rowid=tt), but a new record is redirected to &rowid=0

It's ok if PK is integer.

As a workaround you could add a standard internalid element to your list as PK.
 
hi troester,

thanks for your answer. that is unfortunately a bit difficult now as initially, everything has been taken over from a previous system and all the lists, etc. are now up and running. i wonder what happens to all the existing lists if i add that pk, will that not create major issues like needing to redesign them?
 
hi Hugh's gone into hospital for some back surgery. So sorry to ask you to duplicate info that you have probably already given him, but I tried the log in you supplied in the "your sites" section but I can't log into the admin to take a look at your set up. Could you update those details so I can log into the site's admin?

I'd especially need to see how and where you were generating the primary key value.

That being said, in general if you custom PHP form plugin code was creating and setting the value as follows:
(Note i am using the preferred app->input rather than the deprecated JRequest command, and that I had my plugin set to run "onBeforeProcess" ):

PHP:
$myCode = 'abc123';
$app = JFactory::getApplication();
$app->input->set('myCode', $myCode);

and my redirect plugin has this this jump page
PHP:
index.php?myCode={myCode}

then upon form submission the browser is redirected to :index.php?myCode=abc123
 
Hi Rob,
in case of a non-integer PK a redirect to
&rowid={rowid} or &rowid={table___id_raw} is working if editing an existing record (e.g. redirecting to &rowid=tt),
but a new record is redirected to &rowid=0
the redirect with a non-integer PK is working if it's an existing record.
Only if it's a new record it is redirected to rowid=0.

This is working with an integer PK so maybe there's still some casting to integer done in case of a new record?
 
is this with fabrik 3.1? I can't replicated it and the rowid=0 logic was more of a fabrik 3.0 thing if memory servers
 
is this with fabrik 3.1? I can't replicated it and the rowid=0 logic was more of a fabrik 3.0 thing if memory servers

Hello Rob,

thanks for having a look and sorry for my delay, i was out of town :) i just sent you a message with all connection details and whatever i communicated to Hugh in order to check on that issue.

thanks :)
susanne
 
HI thanks for the message.

I've applied pretty much what I outlined in my previous post. At the end of your PHP scirpt, I set a value 'my_student_id' in the $app->input.

Then I added a redirect plugin to run using a placholder {my_student_id} to re-inject the variable back into the redirect URL.

One gotcha is that as your PHP plugin runs before the form process, you can't use the same names as the fields in the form, as those values are then updated once the form has been processed, hence why I used 'my_student_id' and not 'student_id'
 
HI thanks for the message.

I've applied pretty much what I outlined in my previous post. At the end of your PHP scirpt, I set a value 'my_student_id' in the $app->input.

Then I added a redirect plugin to run using a placholder {my_student_id} to re-inject the variable back into the redirect URL.

One gotcha is that as your PHP plugin runs before the form process, you can't use the same names as the fields in the form, as those values are then updated once the form has been processed, hence why I used 'my_student_id' and not 'student_id'

Thanks a million Rob, that is fantastic, it works like a charm :))))))))))))))))))

here is the code how it looks in the php plugin (onBeforeProcess) where the student_id is created and everything saved, at the end:
$app = JFactory::getApplication();
echo"student no = " . $studentno;
//exit;
$app->input->set('my_student_id', $studentno);

and the redirect plugin has:
index.php?option=com_fabrik&view=details&formid=1&rowid={my_student_id}
 
Sorry Rob, i had to reopen again as i have a slight problem. with form 59 it is very similar (same thing but for a different student type) but this one has a onBeforeLoad and that seems to create a problem. i also tried to however redirect to form no 1 anyway to avoid the onBeforeLoad command as it is not needed when doing the redirect but both ideas are not working :( can you please have a look again if a redirect would be possible?
 
I'd love to but it seems the login to the admin no longer works? Could you re-instate it please?
thanks
 
I'd love to but it seems the login to the admin no longer works? Could you re-instate it please?
thanks

hm that is weird, did you try on the correct demo site? i just logged with the account i told you. please try again, thanks :)
 
odd its working now, so sorry about that
I tried submitting for 59 and the redirect seems to work, I got a redirection URL of
'index.php?option=com_fabrik&view=details&formid=59&rowid=A47806'
but the page tells me it can't find the record, is that the problem?

I took at look at the onbeforeload code but I dont think that should cause an issue
 
odd its working now, so sorry about that
I tried submitting for 59 and the redirect seems to work, I got a redirection URL of
'index.php?option=com_fabrik&view=details&formid=59&rowid=A47806'
but the page tells me it can't find the record, is that the problem?

I took at look at the onbeforeload code but I dont think that should cause an issue

no probs Rob. Yes that is the issue, the record has been saved correctly (also A47807) but it says that it cannot find it. the same procedure works well on the other form. hm, if thought the onbeforeload is the only difference. what else could be the problem in this form?
 
The record is saved, but its the list's second prefilter which is stopping the newly created record from being shown
 
The record is saved, but its the list's second prefilter which is stopping the newly created record from being shown

oh, thanks Rob, i will check on that :) yessssss confirmed, you are soooo right!!! silly me! thanks for pointing that out to me! the filter is correct, of course it is not supposed to show in case we add a testrecord with that wrong info ;) all fine now!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top