This topic is locked
[SOLVED]

 Creating draft pages

4/26/2019 7:42:39 PM
PHPRunner General questions
W
WilliamB authorDevClub member

Hello,
I have an area that staff put in case notes. I have implemented an autosave via ajax to the edit page. I would like to do this on the add page but of course do not have a record ID yet to make sure the proper record is updated. I was thinking of implementing some type of draft page that gets saved via ajax and then when the staff member actually hits add record on the add page it gets added normally. Has anyone tackled this?
Thanks for any input.

admin 4/28/2019

Something like this can be done. Since autosave only works on the edit you will have to create a draft/temporary record and redirect user to that page.

  1. Add a new yes/no field to the table in question, name it "draft" for instance. Draft records will have 'yes' in this field, actual records will have 'no' there. Make sure that on the list page only actual records are displayed.

select ...

from ...

WHERE draft='no'


2. Add page: BeforeProcess event. Create a new record, set draft='yes', redirect user to the Edit page of this record.
3. When record is saved on the Edit page add the following to BeforeEdit event:

$values["draft"]='false';
W
WilliamB authorDevClub member 4/30/2019

Thanks Sergey!
I will try this.
Billy

W
WilliamB authorDevClub member 4/30/2019

It works the way you said. I sorted the list page with tabs. One shows Drafts and the other Published.
Before record added (add page)

$values['Status']='Draft';

return true;


Before record added (edit page)

$values["Status"]='Published';

return true;


After record added (add page)

header("Location: tCaseNote_edit.php?editid1=".$values['ID']);

exit();


The only way I know to save the record on the add page is by forcing a save click to JavaScript OnLoad event

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


Is there a better way to do this? It is not that smooth.