Forums

Limit DB entry per user

HerKle 19 Jul, 2013
Hi,

I am testing a registration form for an event with CF4 on J2.5, which only Joomla registered users can attend.
To prevent people from registering twice, I understood that CF is checking user-id and using "replace" instead of "insert" in the MySql query (I read that somewhere in this forum). Unfortunately this is not working. Every time I test-registered, a new DB record was created instead of updating the first.

How can I make CF check for firstname, lastname and birthday in the DB table, before it either updates an existing record or if not, creates a new record?

By looking for these three fields instead of user id, the attendee can register also his family, without having to create Joomla users for every single family member.

Thanks for showing me the direction.

Regards,
Herbert
GreyHead 20 Jul, 2013
Hi Herbert,

Please see this FAQ. It is the value of the Primary Key column that you need to use to make sure you update the records; usually this is 'id' or 'cf_id' if you created the table in ChronoForms.

Bob
HerKle 20 Jul, 2013
Thanks Bob,

I read that already, but I seem to be blockheaded rigth now:

How can CF know that cf_id of the record before the form is filled with data and saved to DB? When loading the form, it doesn't know anything of the user except his joomla user-id. And when he registered four persons with that same user-id, how to identify the right cf_id?

Solution must be simple, yet I can't see it.

Thanks again!
Herb

PS: I combined the three fields firstname, lastname and birthday in the MySql CF table to a unique index - that at least prevented saving a second record with those same values, but did not replace it with new values for the other fields (eg. date of arrival) which might be changing until the event.
HerKle 20 Jul, 2013
Hi again,

I continued testing - while ignoring the multiple "family" registration of one single user - just to see if at least the updating of an existing record, as described in the faq works.

For example, if the table primary key is 'id' and you have id=99 in your data then if there is a record with an id of 99 it will be updated.



I identify and load existing cf_id from database via joomla user_id, pass it over to the form in a hidden field (I can see the cf_id in the source code of my page!) - and yet that damned DB Save thing adds a record in the table, bravely adding +1 to the cf_id column.

Now I really need help, since I did all by the book, and yet it doesn't work.

Regards,
Herb
GreyHead 22 Jul, 2013
Hi Herb,

Please drag a Debugger action into the On Submit event, then submit the form and post the debug results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab.
HerKle 22 Jul, 2013
SOLVED!

I found out that the preloaded 'cf_id' was converted into a string.

To re-change it into an integer again made everything work.

The only thing, I would like you to do now, Bob, is to include into your valuable checklist on
http://www.chronoengine.com/faqs/2619-my-form-data-isnt-saving-to-the-database-correctly.html

to check whether your input type matching the primary key is an integer



That could help others saving their sunday!

And you might declare this thread as solved, I think, since using 'cf_id' as match solves also the issue with one user registering several persons.

Have a nice start into the week, greetings from Switzerland!
Herb
GreyHead 22 Jul, 2013
Hi Herb,

I updated the second 'arrow' in the FAQ to make it clearer.

Bob
HerKle 22 Jul, 2013
Thanks again, Bob,

but I believe my text more precise, since yours sounds refering to the mysql table field, which is already automatically an integer, if it is primary key ;-)

My problems were caused by the submitted value I sent which was a string to that numeric field...

But anyway, it will help reminding me in maybe two years, when I have to deal again with CF. ;-)
This topic is locked and no more replies can be posted.