Hello,
I've designed a form for updating a database table. It works. The problem is that I can't add a new record through this form. I tried creating a link to the form with the parameter `chronopage=edit` to call it and without an `id` parameter, but the form isn't blank ; it's already populated with the data from the previous open record. Would it be better to create a separate form for adding records ?
Thank you for your insights.
Hi
You need a PHP action at the start of the page to check if the "id" parameter exists or not, if it exists then Read Data, if not then do nothing
You can use the PHP Events behavior for that.
Let me know if you need a screenshot
Hi Max,
Thanks for your response. I begin like this but, yes, I need a sreenshot of what it should be made

Here is how it should look like:

and here is the code:
if(!empty($this->data("id"))){
return "read";
}else{
return "blank";
}
You check $this->data because id will be passed as a query parameter in the form URL
Unfortunately it still doesn't work, my form is still not blank, it is still completed with data from the previous record consulted.I attach a capture (two pictures) for a better evaluation of the pb.


Hi
Try to add the Clear Session action at the start of the editing page:

Does this help ?
According to your image the reading will only happen when the "id" parameter is passed, but once you read it and the data is merged, the data will not be reset until the editing page is submitted, and if you do not do that then the data will stay there.
Hi Max,
Unfortunately, it's still not working. The creation form displays the last viewed record. Can I send you a backup of the form for analysis ? How ?
Thanks a lot.
Hi CDLMQSE
Instead of the Clear Session action, please try a PHP action with this code:
$this->data=[];
Add this action in the "blank" event of the PHP which checks for "id", you can also add that line in the main PHP itself inside the "blank" branch
What do you get ?
Unfortunately, I haven't gotten any better results, but I think I've found the source of the problem and the solution.
In my initial request, I specified that I'm calling a form for a new record, omitting the `id` variable from the URL. However, the condition tests for the variable to be empty or null. Since it's absent from the URL, the condition is never met. So, I've added a null `id` variable to the URL. And it works !

This will work because you pass an empty value to the WHERE statement in Read Data, but you better do it the way I suggested:

That way the Read Data does not run and the data from previous read is reset.
The form is not empty when there is no id parameter in the browser's address bar ?
Does the debug show that the main PHP check is returning "blank" ?
For the latest debug your posted please post the URL in the address bar and screenshots of the Load event of that page
You may also attach the whole form if you like and mark it as "Private"

