Jump to content

Creating page from form based on template fields (front end)


Recommended Posts


I am trying to create a frontend form that allows the user to create a page with a specific template (and fill out the fields)

I have started to use code from this post


This is my current code

$p = $pages->get(1029);
$template = $p->template->name; // this is the template where we will get the fields from

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

// add the page's fields to the form
$fields = $p->fieldgroup;
foreach($fields as $field) {
    $inputfield = $fields->{$field->name}->getInputfield($p);

// add a submit button to the form
$submit = $modules->get('InputfieldSubmit');
$submit->name = 'save_service';
$submit->attr("value", "Go");

// process the form if it was submitted
if($this->input->post->save_service) {
    // now we assume the form has been submitted.
    // tell the form to process input from the post vars.

    // see if any errors occurred
    if( count( $form->getErrors() )) {
        // re-render the form, it will include the error messages
        echo $form->render();
    else {
        // successful form submission
        $np = new Page(); // create new page object
        $np->template = 'service'; // set template
        $np->parent = $pages->get($user); // set the parent
        $np->of(false); // turn off output formatting before setting values

        foreach($np->fields as $f) {
            $np->set($f->name, $form->get($f->name)->value);
        $np->save(); //create the page

        echo "<p>Page saved.</p>";
} else {
    echo $form->render();

And I am getting this error, I can't figure out what it is.

Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /home/dev/public_html/wire/core/Selectors.php line 396)

#0 /home/dev/public_html/wire/core/Selectors.php(439): ProcessWire\Selectors->create('41', '', '')
#1 /home/dev/public_html/wire/core/Selectors.php(159): ProcessWire\Selectors->extractString('41')
#2 /home/dev/public_html/wire/core/Selectors.php(145): ProcessWire\Selectors->setSelectorString(Object(ProcessWire\User))
#3 /home/dev/public_html/wire/core/PagesLoader.php(217): ProcessWire\Selectors->init(Object(ProcessWire\User))
#4 /home/dev/public_html/wire/core/Pages.php(232): ProcessWire\PagesLoader->find(Object(ProcessWire\User), Array)
#5 /home/dev/public_html/wire/core/Wire.php(383): ProcessWire\Pages->___find(Object(ProcessWire\User), Array)
#6 /home/dev/public_html/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___find', Array)
#7 /home/dev/public_html/wire/core/Wire.php(439): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'find', Ar

This error message was shown because: you are logged in as a Superuser. Error has been logged.


  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...