Jump to content

How do you update a page with all its field via front-end?


Marc
 Share

Recommended Posts

I'm just getting started and have looked for ways to update a page including its fields via a front-end form, but I'm missing a few pieces of the puzzle. Here's what I have, mostly borrowed from posts on this forum:

$page = $pages->get('1015'); // get some page

// make a form
$form = $modules->get('InputfieldForm');
$form->method = 'post';
$form->action = './';

// add the page's fields to the form
$form->add($page->getInputfields()); 

// add a submit button to the form
$submit = $modules->get('InputfieldSubmit'); 
$submit->name = 'submit';
$form->add($submit); 

// process the form if it was submitted
if($input->post->submit) {
    $form->processInput($input->post);
    $page->save();
    echo '<p>saved</p>';
}

// render the form output
echo $form->render(); 

I think the problem is that I have to loop through the form inputs and save them individually? How would I do this?

  • Like 1
Link to comment
Share on other sites

Take a look at Soma's gist.

It loops through all the fields of your page and displays a form.

Then on Submit of the form it again loops through each field and saves the value.

It also includes all styles and scripts that you need for your form to work on the frontend.

This is working great for my frontend form.

If you need help implementing it, let us know.

  • Like 6
Link to comment
Share on other sites

I unfortunately don't have an answer to your specific question (I'm rather new to ProcessWire myself), but have you seen the "Fredi" module: http://modules.processwire.com/modules/fredi/

It will handle the front-end editing for you.

Yeah I looked at that, it's a nice solution but not quite what I had in mind. Thanks for the suggestion though.

Take a look at Soma's gist.

It loops through all the fields of your page and displays a form.

Then on Submit of the form it again loops through each field and saves the value.

It also includes all styles and scripts that you need for your form to work on the frontend.

This is working great for my frontend form.

If you need help implementing it, let us know.

Looks like there's a lot of cool stuff to find down there, thanks for the link!

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