Jump to content

Uploading multiple PDFs in repeater field


dowmedia
 Share

Recommended Posts

Hello All,

I am trying to upload multiple PDF files into one repeater field.

The exact situation is, if someone submits the form.

  • make newItem in repeater
  • add all the PDFs in newItem.

every thing is working without repeaters(files not getting replaced). But in repeater, only last file remains exist.Other PDFs getting replaced from the newItem field of repeater.

My code looks like-

$p2= pages->get($id);
$pdfs = new WireUpload('f_plan'); 
    $pdfs->setMaxFiles(8);
    $pdfs->setOverwrite(false);
    $pdfs->setDestinationPath($upload_path);
    $pdfs->setValidExtensions(array('pdf','xps'));

// execute upload and check for errors
    $pdf_files = $pdfs->execute();
    echo count($pdf_files); //count is working
    if(!count($pdf_files))
    {
    $pdfs->error("Sorry, but you need to add a photo!");
    return false;
    }
    
    foreach($pdf_files as $filename)
    {
    $p2->of(false);
    $new_rep = $p2->floor_plan_rep->getNew();
    $p2->save();
    echo $pathname = $upload_path . $filename;  //all the urls are okey
    $new_rep->floor_plan = $pathname;     
    $p2->save();
    $p2->of(true);
    unlink($pathname);
    }
   

Also it is making one extra blank repeater field inside repeater.(I know something is wrong and something is missing in my code. :undecided: ).

Please help.

Thanks

Link to comment
Share on other sites

  • 2 years later...

I had this exact same problem trying to save multiple repeater pages and came here from Google.
I know it is listed in the docs (i didn't read correctly) but i will add the answer here for any future googlers.

Taken directly from the docs.

$building = $page->buildings->getNew();
$building->title = 'One Atlantic Center';
$building->feet_high = 880;
$building->num_floors = 50;
$building->year_built = 1997;
$building->save();
$page->buildings->add($building);
$page->save();

 

 

When creating a new repeater page you need to save it and add it to the repeater field on the page and then save to page.

With hindsight it's pretty obvious but i wasted way to much time wrapping my head around it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...