Forums

How to spit a string field by separated value

MarkHoward99 20 Jun, 2018
I'm setting up a form with three fields, the first two are for name and email. The third is a text field where users will type a list of courses, each separated by a comma.

What I want to do is save the email and name into one table and then split courses into individual records in another table that is linked to the first through its ID as a foreign key.

Hence:
tbl_one
ID - 1
Name - John
Email - john@abc.com

tbl_2
ID - 1
Course - Art

ID - 1
Course - Ceramics

ID - 1
Course - Painting

I've tried using the Event Loop function and referred to the manual but can't make it work to show the array or save any data into another table - as it shows in the manual and examples I've seen on the forum.

With not being familiar with how all this stuff works and unable to find any other noobie tutorials I could really do with some advice on how it's supposed to work.

I'm trying to understand where things are defined in the Loop Event info, specifically:

Where would you define the comma separator for the course field?
Where do you specify the foreign key for the linked table?
Is the Data Provider name just a random variable name or does it have to relate to a form field or something else?


This is the form and debugger information but doesn't show the information as per any of the other examples I've previously seen.

Thanks for any help.



GreyHead 21 Jun, 2018
Hi MarkHoward99,

You can use the PHP implode() method to convert a comma separated string to an array. - then use trim() on the array values to clean up any stray spaces.

However, I'm dubious about allowing free text there as you can get all kinds of messy results. A Checkbox group, or an Autocompleter with multi selection enabled might get you better data.

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