Welcome Guest, Not a member yet? Register   Sign In
Forms Helper - dynamically add fields & handle them correctly
#1

[eluser]Unknown[/eluser]
Hi all,

Apologies if this is a duplicate - I can't find anything helpful on the forum search...

I have inherited an existing ci website which has several forms in the admin area created using the forms helper.

One of these forms is for managing events, and I need to add the ability to list multiple (varying number per event) ticket types and prices.

So essentially I'll have a group of fields such as:
* Ticket Type
* Ticket Price
* Quantity Available

And a user needs to be able to replicate these fields multiple times to add each ticket type.

I can replicate the fields without issue with jquery's .clone method, and I can set the field names to arrays[] so each gets submitted in the $_POST data. But wondering if there's a more 'baked in' way of handling this that makes the error handling / db write etc easier?

Thanks in advance for any pointers,

Max
#2

[eluser]t'mo[/eluser]
Treating your form fields as arrays will probably help. You can use square brackets and indexes inside the form field names, then parse them out in your PHP code when handling the POST. Here is an example.




Theme © iAndrew 2016 - Forum software by © MyBB