Jump to content

Form processing on front-end, dynamic forms and creating page


Vineet Sawant
 Share

Recommended Posts

TL;DR : I'm looking to create dynamic forms which will take fields list from given template & create/save pages dynamically.

Hello,

I've been using PW for a while for creating web applications like ERP systems and similar applications which have tons of forms.

So far I've been creating, processing & validating them manually. While researching I found this link which I found to be very helpful.

Code given in that example allows user to create a form based on the fields of any page and save it, which is very cool.

Based on that code I tried doing something like this:

$p = new Page();
$p->template = "mytemplate"; //I've added few fields to this template
$p->parent = "/someparent/";
$p->of(false);

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

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

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

// process the form if it was submitted
if($input->post->submit){
	$form->processInput($input->post);
	$p->name = date(dmYhisn);
	$p->save();
}

It did create a page but without any data. I know this could be a very stupid thing to try, but I guess it was worth it.

More research taught me that probably using ProcessPageAdd module I can create new pages. But I don't know how exactly that works.

I'm looking for some guidance about modules & their use on fron-end.

Thanks.

Link to comment
Share on other sites

I write a module FormHelper to create Frontend forms Form page, template vor array oft field data.

https://processwire.com/talk/topic/7508-template2form-module-helper/

Next module will be a frontend content manager (edit and create pages based on FormHelper module).

Hi, your module looks great. Can I use it for any kind of template? Cause the forms I want to process can be of any size, mostly they'll have tons of fields.

Also, is it published? I'd love to give it a try.

Thanks a lot.

Link to comment
Share on other sites

It isn't tested with multi language fields or something like repeater fields at the moment.

You can generate a form based on saved pages and get a prefilled form as default. 

Create a form from template fields works with a "fake page" (created but not saved page object), but so you can't use a template with image / file fields that way. You'll get an error message. Maybe it works if the fake page gets saved before the form is generated. I'll see during page add funtion of planned frontend content manager (instead of use a template based form the module create and save the needed page before generate the form via FormHelper.

For use with me UserLogin module the third way was added. The login form is defined as data array. Should be the same problem with image / file fields, but haven't tested it...

I puplished the module code at the last topic post, but not released a module as yet...

Module will be released after code cleanup, but it isn't tested enough to be stable!

Link to comment
Share on other sites

  • 3 weeks later...

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