rado
Posts: 221
|
| Posted: 10/16/2009, 3:21 PM |
|
Hi
Maybe it's simple, maybe not, but somehow I can't find out the way to change the action from insert to update after the row is inserted in db. I want to have edit mode for the same record that was just inserted. I tried to set "Preserve parameters" to "GET and POST" and all data left in the record form but the action is still "Insert" (since my update and delete buttons are not available, just "Add" button)
Thanks,
Rado
|
 |
 |
rado
Posts: 221
|
| Posted: 10/16/2009, 3:58 PM |
|
I tried with this code in after insert event but it doesn't work.
$paymentsParent->InsertAllowed = false;
$paymentsParent->UpdateAllowed = true;
$paymentsParent->DeleteAllowed = true;
Any idea?
|
 |
 |
rado
Posts: 221
|
| Posted: 10/16/2009, 4:15 PM |
|
OK,
I found the way.
In after insert event, I retrieved the "last insert id" and set it as session variable which I used as datasource parameter in record form.
Thanks,
Rado
|
 |
 |
datadoit
|
| Posted: 10/16/2009, 5:35 PM |
|
May be a little cleaner to add to the AfterExecuteInsert event:
global $Redirect, $FileName;
$qs = CCGetQueryString("QueryString","");
$qs = CCRemoveParam($qs, "ccsForm"); //Never want this hanging around!
$id = mysql_insert_id();
//Are there other query string params we want?
if ($qs) {
$goto = $FileName . "?" . $qs . "&id=" . $id;
}
else {
$goto = $FileName . "?id=" . $id;
}
//Redirect back to this page if the insert was made.
if ($id) {
$Redirect = $goto;
}
else {
echo "Oops!";
}
If you put the last inserted ID into a session variable, then anytime
going into the record after an insert has already been made will ALWAYS
display that last record inserted. May not be exactly the behavior you
want.
|
|
|
 |
rado
Posts: 221
|
| Posted: 10/16/2009, 6:05 PM |
|
Thanks datadoit a lot,
Actually I got exactly what I need using session variable, but only problem is actually when user click on "Back" button. The session is not reset and every next attempt to create new record failed since the record went automatically to edit mode (the old session variable is still alive). I made link to go to previous page where I clean session variable and in that case it's OK.
It looks like that your proposal is exactly what I need but since I'm not expert with CCS I'm not 100% sure (for some stuff yes) what I need to change in your script in order to adapt it with my page.
For example:
what is:
"QueryString"
"ccsForm"
I'm only sure that "id"needs to be replaced with "my id"
Again thanks a lot for help.
Rado
|
 |
 |
rado
Posts: 221
|
| Posted: 10/16/2009, 6:06 PM |
|
And when I put your script in the AfterExecuteInsert event I got this message:
"Warning:Record : Event AfterExecuteInsert cannot have actions because datasource would not be generated.
"
|
 |
 |
gaetgodi
Posts: 9
|
| Posted: 11/11/2009, 7:52 AM |
|
Thank you datadoit... this worked perfectly for me.
I just changed &id= to &DMAppID and ?id to ?DMAppID to make it relevant to my application.
|
 |
 |