Forums

not saving to db

kclark 03 Apr, 2010
I have done 3 forms so far. 2 are working properly. the 3 is not saving to the db. I was wondering if it is because the first 2 forms is an auto numbering id field and my 3rd form is I want to dictate the ID #.
GreyHead 03 Apr, 2010
Hi kclark,

You'll need to check the table structure, you can't dictate the ID if the column is set as an auto-incrementing Primary Key (unless you are updating an exsiting record). But otherwise it should be OK.

Set Site Debug on in Global Configuration and hunt down the SQL query to see exactly what is happening.

Bob
kclark 03 Apr, 2010
ID is not set to auto increment. It is set as an integer and primary key.

The 2 forms that work have an auto increment id.

I enabled debug, but I am not getting anything with that. I am not receiving any error messages whatsoever. I just use the form click submit and check the database and the info is not there.
nml375 03 Apr, 2010
Hi kclark & Bob,
The problem is, that if you specify the value of the table key, the JTable class (used by ChronoForms) assumes that the post already exists, and should be updated rather than inserted. In order to get around this, you'll either have to implement your own SQL-queries, or build your own JTable-class extension with code that can create a new record in this perticular condition, along with the matching "bind()" and "store()" invocations.
I did something like this quite some time ago, though I don't have the code lying around anymore. I roughly recall having some private _state property determining whether the current instance's data was load()'d or bind()'d, basing the update/insert operation on that _state if the table key is non-nill.

/Fredrik
kclark 04 Apr, 2010
I don't think that is the case. If I change my ID field to an auto increment, my new record will load just fine. The form just won't create the new record with the ID dictated by me.
nml375 04 Apr, 2010
Hi kclark,
That is exactly what I just said. Using the JTable classes, you cannot create (insert) a new record with the primary key ("ID") set. That is regardless of whether your database table has the primary key as auto_increment or not (even if a table column - primary key or not - has auto_increment, you can still overrule this when inserting or updating records using a trivial SQL-query).

If you enable SQL-debugging in your site config, you'll see that if you try to specify the value of the primary key (ID), the query will be an "UPDATE jos_chronocontact_something SET field1=value1, field2=value2 ... WHERE ID=something". If you do not specify the value of the primary key, the query will be an "INSERT INTO jos_chronocontact_something (field1, field2 ...) VALUES (value1, value2 ...)".

Simply put, you cannot specify the value of the primary key for a new record when using the DB Connection in ChronoForms, you'll need some custom code for this.

/Fredrik
GreyHead 05 Apr, 2010
Hi Fredrik,

Thanks - I didn't know that.

@kclark: aplologies for my misleading answer.

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