CGBetterForms Input not sending array values.

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

CGBetterForms Input not sending array values.

Post by WDJames »

Hello,

I'm having an issue with CGBetterForms that is a bit difficult to explain. I have multiple inputs that share the same name which should return an array ie:

<input type="text" id="something1" name="something[]" value="">
<input type="text" id="something2" name="something[]" value="">
<input type="text" id="something3" name="something[]" value="">

However when a user submits the same value for those inputs, there is only one value on the resulting array. Also, when one or all of the inputs are left blank, it does not return an empty array.

Is there any way that blank values are registered as well as duplicates so the array can be something like this:

(" ", "something", " ")
("something", "something", "somethingelse")

I hope I've explained it clear enough.

Thanks in advance.

James
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: CGBetterForms Input not sending array values.

Post by DIGI3 »

I think arrays are only supported in checkbox groups and multiselects, not text inputs. I haven't tested that, but I use checkbox groups and multiselects a lot and the arrays are always fine, and empty when no response is selected.

The module is no longer supported, but if you wanted this feature added you could probably sponsor it for the fork, SmartForms. You could also just make them separate text inputs then combine them into an array either via js on the form itself, or Smarty during processing.
Not getting the answer you need? CMSMS support options
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

Re: CGBetterForms Input not sending array values.

Post by WDJames »

Thanks for getting back to me. Its odd because I've been using the text input's values as arrays on fields that would always have different values (eg names) and it works as expected (the values are added to the array). Just to try give a bit more background to what I'm needing it for:

I have a booking form that has the following fields:

1. Number of attendees - A text input which is attached to buttons that add and remove fields by cloning a div and its contents which are other fields (listed below).

2. Attendee Name - <input name="attendeename[]" value="" required>
3. Attendee ID - <input name="attendeeid[]" value="" required>
4. Additional Info - <input name="attendeeadd[]" value="">
5. Terms Checkbox - <input type="checkbox" name="attendeetc[]" value="checked">

So when a user clicks on the add button for "Number of attendees" the div containing fields 2 to 5 is cloned and when the remove button is clicked the last clone gets deleted. Upon submission, the arrays are collected and processed to be returned as "Name", "ID", "Info", "Terms" for each of the attendee.

However, when fields 4 and 5 are left blank (as they are not compulsory) the results fail altogether. I suppose what I'm after is for the blank fields to always return something even when left blank so it ends up as "Name", "ID", " ", " ".

Apologies for the long reply but I hope this explains it better.

Thanks,

James
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: CGBetterForms Input not sending array values.

Post by DIGI3 »

Without modification to the module I think you'd just need to give them a value when empty, like x or 0 or something. Or, as I said, see if it's a feature that the developer of SmartForms could add then migrate to that.
Not getting the answer you need? CMSMS support options
WDJames
Forum Members
Forum Members
Posts: 64
Joined: Tue Feb 13, 2018 1:09 pm

Re: CGBetterForms Input not sending array values.

Post by WDJames »

DIGI3 wrote: Tue Jan 24, 2023 4:50 pm Without modification to the module I think you'd just need to give them a value when empty, like x or 0 or something. Or, as I said, see if it's a feature that the developer of SmartForms could add then migrate to that.
I think thats the only option I can explore as I am not able to migrate to SmartForms (well not in the short term anyway). I'm hoping there is a way to give them a value when empty that doesn't use javascript. Thanks for your help.
Post Reply

Return to “Modules/Add-Ons”