Problems saving data in CFv4

DShapiroNaples 13 Jul, 2012
I am using two forms one (http://www.mealplanningmaven.com/index.php?option=com_chronoforms&chronoform=mpm_client_master_list) to edit a list of current clients of redirect to the second form (http://www.mealplanningmaven.com/index.php?option=com_chronoforms&chronoform=mpm_client_master_list) which is used to either add or edit a current client.

When I use the second form to edit it works fine, but when I am redirected to the second form, by clicking on the "New Client" button, and add a new client the Save to DB does not work.

I have left on the debug just before the Save to DB in the On Submit Event.

Any help would be appreciated.

I am CFv4 Latest Release, J1.5
GreyHead 14 Jul, 2012
Hi DShapiroNaples,

It looks as though the New Client form requires a User ID which presumably doesn't exist for a new client? I'd guess that you need to remove that requirement and probably hide the input for new clients.

Bob
DShapiroNaples 14 Jul, 2012
Bob
The clientid is a required field and is the primary key.
When I enter all of the data the db store does not insert
the data into the table. Try using clientid 222 as a new id.
DShapiroNaples 14 Jul, 2012
Here is what I beleive is going on... the $row->store function in the DB Save function is recognizing that the primary key (clientId) is alresdy set and therefore assumes this should be an UPDATE rather than an INSERT sql statement. The issue here is, I beleive, the JTable function is assuming you will always have a SQL generated primary key.

I have a user-defined primary key, clientID, that is entered by the user. I am not sure how to best work around this unless I write the database INSERT or UPDATE myself and not use the DB Save action.

After researching, it appears that I am correct, the Joomla JTable store function will only create a new table row if the PK field is not filled in. This would require that the table PK be a auto-increment value.

To solve the problem I altered the table to use a separate auto-incremented PK. I created a hidden box with the new PK as the field name and changed the first form to send a token parameter of the PK field (clientPK) to the second form.

I am going to have to adjust my table design accordingly.
GreyHead 15 Jul, 2012
Hi DShapiroNaples,

Yes, you've described the way the Joomla! DB classes work using 'bind, store, save'. And I'd do what you have and use a second column to hold the Client ID.

You could get round this the other way by hand-coding the DB save but it's probably more work that way.

Bob
This topic is locked and no more replies can be posted.