Adding array values to db table

chriso0258 01 Jun, 2012
One of my form inputs (mbr_info) takes a users first and last name.
<input type="text" name="mbr_info[][first_name]"/>
<input type="text" name="mbr_info[][last_name]"/>

If they are signing up family members, they can click a button to add another row for each member and add their first and last name. Below is the output of some sample data showing this.

Array
(
    [chronoform] => mbrship_form
    [event] => submit
    [Itemid] => 644
    [option] => com_chronoforms
    [view] => form
    [membership] => 100
    [mbrshp_date] => 2012-07-01
    [mbr_info] => Nobody, Important, Somebodys, Watching, Goin, Fishin
    [address1] => 456 Fake St
    [address2] => 
    [city] => Nowhere
    [state] => AL
    [zip] => 45678
    [phone] => (555) 555-1212
    [email] => none@example.com
    [chrono_security_answer] => 
    [chrono_verification] => 8vmhj
    [status] => y
    [input_submit_9] => Submit
    [776cad74b53a712c5f9ea84ab11a3793] => 1
    [item_name] => TCA Patron Membership
    [expires] => July 01st 2013
)


When I try to create a db table, I get the following message:

Field name "mbr_info[first_name]" is invalid, please fix the field name in the wizard (or the form code) then retry again.
Field name "mbr_info[last_name]" is invalid, please fix the field name in the wizard (or the form code) then retry again.


The db table should have field name for first_name and last_name. I don't care that the db table contains the above information (address, phone, email, etc) for each person in the array.

I tried configuring the form initially for one first_name and last_name (no array) and then put the array back in after the table was created; I used the "Handle Arrays" action but that didn't work. Is there a way to do this?

Thanks.
GreyHead 02 Jun, 2012
Hi chdri0258,

This debug output [mbr_info] => Nobody Important, Somebodys Watching, Goin Fishin is presumably after a Handle Arrays action? Otherwise the error doesn't make sense to me.

The raw data - before the Handle Arrays action presumably looks something like this:
mbr_info => array( 
  [0] => array(
    [first_name] => 'Nobody',
    [last_name] => 'Important'
  ),
  [1] => array (
    [first_name] => 'Somebodys',
    [last_name] => 'Watching'
  ),
  [2] => array ( 
    [first_name] => 'Goin',
    [last_name] => 'Fishin'
  )
)
But then I'm not sure what you actually want saved? Just the first value? or each of them in a separate record?

Basically you can't use [] in a MySQL column name so that causes the error, but you can edit the names and/or add new columns in the Create Table form if that helps.

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