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 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(); } } }  
    • By MateThemes
      Hello everyone!
      I am working with Processwire since some time. But some topics are quite hard for me.
      I have a Portfolio (Gallery) Page.
      I am build a template with Portfolio Index and pages with portfolio entries.
      Structure:
      Portfolio Index
      -- Portfolio Entry
      -- Portfolio Entry
      and so on.
      Portfolio Entry has an Image field with max 12 images and are accessible Templates. 
      Now I want to display the single Portfolio Entry on the Portfolio Index and Paginate them. In the index page all images of a single Entry page should be displayed (I should not be organized as albums, where a random image of the portfolio entry should be displayed). 
      I have no clue to achieve this. May someone could give me an advice.
      Thank you in advance!
    • By ngrmm
      I have a page with a table. Each table row has a page-reference field and a checkbox.
      The Page sends emails to all users (page-refrence->email-field) and change the value of the checkbox in a row to 1.
      It works with this:
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?> But i have to use a variable in my emailbody.inc which i'm able to get in the table-loop.
      So i do the including of the body inside my loop. But this doesn't work anymore. Page sends out the emails but is unable to change the value of the checkbox.
      I get no errors!
      I'm using ProTable
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?>  
×
×
  • Create New...