Tuesday, September 1, 2009

Re: Array of input text

Here's what I've done in the view:

    <div id="BlogUrls">
        <?
        $i = 0;
        for($i = 0; $i < sizeof($this->data['Blogurl']['url']); $i++){
            echo $form->input("Blogurl.url.$i", array('label' => 'URL'));
        }

        ?>
    </div>

    <div id="BlogUrlRow" style="display: none;">
        <?echo $form->input('BlogurlUrl', array('name' => 'data[Blogurl][url][]','id' => '', 'label' => 'URL'));?>
    </div>
    <a href="#" onclick="$('#BlogUrls').append($('#BlogUrlRow').html());"><?__('Add URL');?></a>


In controller, I had to validate manually each URL since the saveAll() method won't work because of the non-conventional field names.



May be there's a better solution to deal with this problem if you know exactly how many URLs you're expecting to receive; but in this case user may add many URLs as he desires.


Of course guys don't do this at home; and ensure you're under an adult supervision if you want to do it; and always remember to use Cake conventions and methods (that's why we are using a framework).


Thanks guys for your help and cooperation!




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: