Jump to content
Vineet Sawant

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

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.

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
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.

  • Similar Content

    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
      Thanks! 
    • By benbyf
      I have a a form in my site footer that can be accessed anywhere on site, I've added the form in the _inc.php file and added the render in the pages footer.php. However, this works well on the homepage e.g. you can submit said form and get a thank you on reload, doesnt work at all on other pages... Just lots like a fresh reload. Any thing im doing wrong here or ways to diagnose as there isn't an error log for formbuilder etc...?
    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By Guy Incognito
      This short script loops through some images from an XML feed and pushes new ones to an image field. It all works perfectly, except for some reason the last image (only) in the loop each time doesn't receive the image description... can everyone spot why? TIA! 🙂 
      foreach ($propertyImages as $img) { $fileName = trim($img[0]); if ( !empty($fileName) ) { $imgPath = '../property_data/'.$fileName; if(file_exists($imgPath) && !in_array(strtolower($fileName),$currentImages)) { $p->property_images->add($imgPath); $p->save(); $newImg = $p->property_images->last(); $newImg->description = $img[1]; $p->save(); } } }  
×
×
  • Create New...