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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Atlasfreeman
      Hi!
      I want to make a small site, a one page site.
      And i have this idea about doing 2 to 3 diffrent template that i can load into the index / home page.

      I want to do this with an array so that i can keep creating more topics (with the template) id needed.
      <?php include('./head.inc'); // include header markup ?> <?php $children = $page->get('template=onecolmn|twocolumn, sort=sort'); foreach($children as $child) { include($child); } ?> <?php include('./foot.inc'); // include footer markup ?>  
      As you can see i have to template wish i want to control from the backend.
      I know include does not work this way, put what is my other option to make an array that loads the whole page on an other pages.
       
       
    • By jom
      Hi everyone
      It seems that I don't fully understand the wireTempPath() function and I need some help.
      I use wireTempPath() to create a new location in assets/cache/WireTempDir and than copy a pdf from the assets/files/page folder to the new folder. I want the file to be accessible only for a limited time, that's why I use wireTempPath.
      The file seems to be copied to the right location, but gets deleted right afterwards, according to 
      As mentioned in the topic above, 
      $wireTempDir->setRemove(false); prevents the file to be deleted. But I like the file to be automatically deleted after a few days. So, how can I do that?
      My code so far (everything works, but the automatic removal of the tempDir folder):
      //generate and show download link $folder = time(); // timestamp as temporary folder $maxAge = (int) $settings->options_downloadlink_valid_hours * 3600; //tempDir wants maxAge as seconds $options = array( 'maxAge' => $maxAge ); $wireTempDir = wireTempDir($folder, $options); $wireTempDir->setRemove(false); $src_file = $page->ebook_download->filename; // Create a new directory in ProcessWire's cache dir if(wire('files')->mkdir($wireTempDir, $recursive = true)) { if(wire('files')->copy($src_file, $wireTempDir)){ //get subdirs from tempDir: $pos = strpos($wireTempDir, "WireTempDir"); $subdir = substr($wireTempDir, $pos, 100); $out .= "<p><a href='" . wire('pages')->get('template=passthrough')->httpUrl . "?file=" . $subdir . $page->ebook_download->basename . "' target='_blank'>$page->title</a></p>"; } } I appreciate any ideas - thanks!
      Oliver
    • By VeiJari
      Hello forum, this is my first security related post, so I'm a bit of a newbie.
      I understand that when I have direct front-input from user I should sanitize the input, but how about when I use a secret key for showing a API for a third-party supplier? Should I sanitize the input->get() key?
      I've tested this issue and I tried ?key=<?php echo $page->field; ?> And without adding any sanitization it comes back: /?key=<?php%20echo%20$page->field;%20?>
      So can I rely on this, or should I still use $sanitizer just in case?
       
      Thanks for the help!
    • By EyeDentify
      I have been experimenting with the new $page->meta() method and find it useful.

      Once i figured out that the data i "save" with it is tied to the page where i called the method from.

      So this is not obvious at least not for me in the documentation:
      https://processwire.com/api/ref/page/meta/
       
      So i just wanted to share that revelation with the community so you don´t get as confused as i was.

      Happy Coding Everyone.
    • By louisstephens
      Going through my long quest to get better with ajax and utilizing the api, I have hit yet another roadblock. I currently have a form with an image field (thanks to flydev for getting that sorted), "title" text input, and a select field set to multiple. In my ajax call, I added in:
      tags = $("#select-tags").val(); form_data.append('tags', tags); $.ajax({ type: 'POST', data: form_data, contentType: false, processData: false, url: '/ajax/upload-preview/', success: function(data) { console.log("Woo"); }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); } }); And in the ajax template: 
      $tags = $sanitizer->text($_POST['tags']); $image = $sanitizer->text($_POST['image']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->tags = $tags; $p->save(); If I select a "tag" from the select input and submit, it does indeed add it to the Page Reference field in the backend. However, this does not work with an array being passed to it of multiple options.

      So it does appear that my ajax call is trying to submit multiple options, but I am really just unsure how to get these two added in. I saw in other forums posts of add($page) and even add(array()). Do I need to handle this js array differently or do  I need to foreach through the $tags to add it like:
      foreach($tags as $tag) { $p->tags->add($tag); $p->save(); } I tried this approach, but apparently I am still missing something.
       
      Edit:
      I was doing some tweaking, and I know I can split the js array out like:
      for (i = 0, len = tags.length; i < len; i++) { console.log(tags[i]); } However, I am not sure then how to handle the POST in php if I were to split it out.
×
×
  • Create New...