TOPIC:

Save checkbox group values to db then retrieve them and populate group 2 years 6 months ago #247384

  • Topic Author
  • Rokhi
  • Offline
  • Senior Member
  • Senior Member
  • Registered
  • Posts: 158
  • Thanks: 1
Hi
I have a checkbox group on a BF form with 8 checkboxes.
The form is opened by a logged in user and data completed.

On submit, I want to save the values to a profile table in the same format as they are saved to the form_records table - i.e. comma-delimited string of numbers (2,4,6)

Then, the next time that user opens the form, I want to retrieve those values from that table and repopulate the checkbox group.

What I'd like to know or have a link to instruction for is:

1) should the repopulating be done in the initialization script or the before form piece (can I get to the database from the script)
2) What element naming conventions, functions or object references can I use either in the script or PHP to extract to store and then repopulate the checkbox group.
3) I looked at using ff_setChecked('name','value') in the before form piece to populate the group but don't know which element name format to use for name and what value relates to in a checkbox group. I am assuming I iterate through group elements and setChecked() for each one.

Thanks

Please Log in or Create an account to join the conversation.

Save checkbox group values to db then retrieve them and populate group 2 years 6 months ago #247386

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Registered
  • Posts: 12079
  • Thanks: 780
Hi,

to populate a checkbox group with database values you have to use a little bit of PHP in the Before Form piece which you can find here:
crosstec.org/en/support/online-documenta...ct-list-from-db.html
This is example for select list, but it should works also with checkbox group

ff_setChecked('name','value') -> this is only for single checkboxes, not for checkbox group.

Hope this helps

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Save checkbox group values to db then retrieve them and populate group 2 years 6 months ago #247387

  • Topic Author
  • Rokhi
  • Offline
  • Senior Member
  • Senior Member
  • Registered
  • Posts: 158
  • Thanks: 1
Thanks for that.

The example will replace the whole group, labels and values, which I don't want to do.

What construct would I use in PHP to iterate through all the group elements to collate the element states and create an output string with the numeric values relating to the items checked - the same as is currently stored in a forms_record. (e.g.2,4,6 where checkboxes 2,4 and 6 are checked)

Please Log in or Create an account to join the conversation.

Save checkbox group values to db then retrieve them and populate group 2 years 6 months ago #247450

  • Topic Author
  • Rokhi
  • Offline
  • Senior Member
  • Senior Member
  • Registered
  • Posts: 158
  • Thanks: 1
OK, did a bit more research - you were right. That code does the trick ok - just needed to understand how to use it. Name and value params relate to the actual name and value set up in the form element. (switch;name;value - e.g. 0;name1;value1). Obvious when you think about it!

So now I can save the values to a profile and retrieve them to populate the form.

Thanks for your help

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.051 seconds

Support Chat

Join our Discord chat and enter the Crosstec channels for live-support, chat forums and interact directly with the community!

After joining, please enter the Crosstec Area and use the #crosstec-support or #crosstec-general channels.

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Subscribe to news and updates!

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here and enter the Crosstec channels to receive live support and talk directly to the team!