Add new record in my database

CDLMQSE 4d ago

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.

Max_admin 3d ago

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

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
CDLMQSE 3d ago

Hi Max,

Thanks for your response. I begin like this but, yes, I need a sreenshot of what it should be made

Max_admin 3d ago
Answer

Here is how it should look like:

Add new record in my database image 1

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

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
CDLMQSE 2d ago

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.

Max_admin 8h ago

Hi

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

Add new record in my database image 2

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.

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
CDLMQSE 3h ago

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.

Max_admin 2h ago

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 ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.