I just made such a feature 2 weeks ago using a simple javascript
function to generate more input fields with file as type. I attached
that function to a button "Add files" and that is.
You need than in controller to write a loop to parse all the array
from $_FILES and for each file do call a "save()" function.

Here is an example jQuery function ( this function has to be in your
ctp file ):
function addmorefiels(){
    $('#yourDiv').append('<input type="file" name="myfilesforupload[]"
value="">');
}

The you need in your form .ctp file some div where you push/attach new
dynamically input fields:
<form....>
...
...
<div id="yourDiv"></div>
<a href='javascript:void(0)' onclick='addmorefiels()'></a>
</form>

Than, in controller in save() function you check the array from
"myfilesforupload":

if( is_array($_FILES["myfilesforupload"]) &&
count($_FILES["myfilesforupload"])>0   ){
   foreach($_FILES["myfilesforupload"] as $distinctFile){
       ... here you have to call your upload class and to save the
files
   }
}

If you want to do this without page refresh than you have to use $ajax
from jQurey :)

On 15 Mai, 22:22, Rob <[email protected]> wrote:
> Let me start off by explaining what I want to do and where I am right
> now.
>
> I have a CakePHP site where I can submit projects, and each project
> has many different elements attached to it.  I'm created the add
> project form to be able to add elements as well.  I have successfully
> created a form that will submit both projects and elements.  This form
> has 2 parts to it the Project form which there is only one and the
> Element form which I want there to be many of.   So for one project
> submission there will be more than one element submission.
>
> What I want to do is add a button that, when clicked, adds another
> Element form to the page until there are enough.  My original idea was
> to do this with AJAX and jQuery, since the form creation is handled by
> cake.  Problem is, I don't really know where to get started.
>
> Any push in the right direction would be helpful
> Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to