Friday, August 28, 2009

Array of input text

Guys,

I'm working in a project where many URLs can be entered for a blog. Let's say Blog hasMany Blogurls; and I would like to show the well known "add more" link to the form so user can add new URL fields when all are filled.

As far as I know, this code:

echo $form->input('Blogurl.url.1', array('label' => 'Other URL'));
echo $form->input('Blogurl.url.2', array('label' => 'Other URL'));
echo $form->input('Blogurl.url.3', array('label' => 'Other URL'));

Will work creating this:

<input type="text" id="BlogurlUrl1" name="data[Blogurl][url][1]">
<input type="text" id="BlogurlUrl2" name="data[Blogurl][url][2]">
<input type="text" id="BlogurlUrl3" name="data[Blogurl][url][3]">


To add more, I would like to get Cake to generate this kind of input:

<input type="text" id="BlogurlUrl1" name="data[Blogurl][url][]">
<input type="text" id="BlogurlUrl2" name="data[Blogurl][url][]">
<input type="text" id="BlogurlUrl3" name="data[Blogurl][url][]">


So I can write one of them inside a display:none'd DIV and append it when the user clicks on the Add More button.



I can't find the proper way to do this. I thought in apply some JS modifications in the original field and then append it's code to the form; but will be very messy.



Other choice is to make a small modification in the framework, or extend the Helper class; but I know this is not a good idea.

What do you think? Have you ever seen yourselves in this situation?

Thanks and happy coding.





Nicolás Andrade
nmac@nicoandra.com.ar
Blog | CV | Flickr | Del.icio.us | LastFM


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: