Jump to content

Recommended Posts

Posted

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! 

Posted
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

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
×
×
  • Create New...