Jump to content

Handling repeater fields in front end forms


neonwired
 Share

Recommended Posts

I have a front end form for creating new pages, repeater and repeater matrix field don't seem to save any data. I was considering handling the data manually but can't seem to get anything useful from the post data, are there any methods i can use?

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 8 months later...

@neonwired @Pip

I know the thread is a bit old, however it was my turn to look for some functionality, and I've found a write-up that would seem to work or at least to be a good start for your needs and mine as well

Not sure if I understood correctly your need, but if you need to just modify the values of Repeater fields from the frontend, I believe this would help you resolve the need ?

Link to comment
Share on other sites

  • 3 months later...
On 5/20/2020 at 3:18 AM, neonwired said:

I have a front end form for creating new pages, repeater and repeater matrix field don't seem to save any data. I was considering handling the data manually but can't seem to get anything useful from the post data, are there any methods i can use?

You need creating form using dynamic row

<input type="text" name="fieldname[]">

Then, using this php code to fill the repeaters

<?php
$fields = count($_POST['fieldname']);
$p = new Page(); 
$p->template = 'template_name'; 
$p->parent = $pages->get('/parent_name/');  
$p->name = 'page-name';
for ( $i=0;$i<$fields;++$i ) {
  $repeater = $p->repeater_name->getNewItem();
  $repeater->field_in_repeater = $input->post->fieldname[$i];
  $repeater->save();
}
$p->save();

 

  • Like 1
Link to comment
Share on other sites

  • 5 months later...

I am trying to put together a front end form for a repeater field. The solution in the previous post gives helpful clues, but my repeater field doesn't need new pages and templates I think - isn't that a Page Reference field?

My repeater field is for RSS feeds; name 'feeds', type 'Repeater'. The field used by 'feeds' is name 'rssfeed', type 'URL'.

To store a regular field I'd use something like this:

Spoiler
if($input->post->updatefullname) {
 $user->of(false); // turn off output formatting
 $user->fullname = $sanitizer->text($input->post->fullname);
 $user->save();
}

 

But instead of one value it would be adding one or more values to an array, somehow done with the fieldname[] and for ( $i=0;$i<$fields;++$i ) stuff, but without new Page() and template etc.? Not sure how to put that together, will try things this weekend...

Is there a code example somewhere?

Is there a way to get the same fancy repeater input field as in the admin area?

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...