Jump to content

populate repeaterfield from form


Albert
 Share

Recommended Posts

Hy, 

I cannot get it going. I try to update a repeater field, containing username, email, a int value, a addresse and a description. I post the data to a handlerfile. So far so good. 

But how can I save the data to the field? 

The Pages is under home and contains a repeater_field named multi_locations -> this should be updated. 

 

My try so far: 

if ($input->post) {

// $p = new Page();
// $p->of(false);
// $p->parent = $pages->get(1);
// $p->template = $pages->get('probleme');

var_dump($p);


$melder = $sanitizer->text($input->post->melder);
$email = $sanitizer->email($input->post->email); 
$location = $sanitizer->text($input->post->location);
$urgency = $sanitizer->selectorValue($input->post->inlineRadioOptions);
$description = $sanitizer->text($input->post->description);

echo $melder . "| " . $email . "| " . $location . "| " . $urgency . "| " . $description;

$p->multi_locations->title = "tryout";
$p->multi_locations->melder = $melder; 
$p->multi_locations->mailadresse = $email; 
$p->multi_locations->map->address = $location; 
$p->multi_locations->urgency = $urgency; 
$p->multi_locations->beschreibung = $description;



//$p->save();

 

Please help me bring some light into the dark.

 

Thank you in advance! 

Link to comment
Share on other sites

13 minutes ago, Albert said:

I try to update a repeater field

Try this:

$repeaterItem = $page->multi_locations->eq(0);
$repeaterItem->of(false);
$repeaterItem->title = "tryout";
$repeaterItem->melder = $melder;
//etc for other subfields
$page->save('multi_locations');

This will change the values for the first item in the repeater field. You can use eq(n) or first() or last() depending on your needs.

That is for updating an existing repeater item, but if you're creating a new page, then you need to add a new item to the repeater:
https://processwire.com/api/fieldtypes/repeaters/

and also read this post:

https://processwire.com/talk/topic/6435-cant-figure-out-how-to-create-a-repeater-through-the-api/?do=findComment&comment=62987

Link to comment
Share on other sites

7 minutes ago, Albert said:

But I cannot just make a new repeaterfield? 

If so then I have to go with pages instead...

Do you mean a new item in an existing repeater field? This post shows how to do that:

https://processwire.com/talk/topic/6435-cant-figure-out-how-to-create-a-repeater-through-the-api/?do=findComment&comment=62987

Is that what you are wanting?

 

  • Thanks 1
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...