Jump to content

Module want: form builder


apeisa

Recommended Posts

Ryan, I haven't actually tried this FormBuilder module recently, so it's possible it needs an update. But first I wanted to check -- do you have any file fields on that form? Based on the error message, it sounds like that might be the case, but let me know... I was really only thinking of that FormBuilder as being for the more basic fields (like text and textarea), as the other types have more javascript dependencies making them really only appropriate for admin use at present.  And of course, this FormBuilder is not a core module, it's more an example to build from. But a real FormBuilder will be in the works later this year.

Link to comment
Share on other sites

  • 4 weeks later...

I finally tried this module out, and it still works in new 2.1! Thanks for the example Ryan.

But it throws an error if it's saving the form as page:

Exception: Method Page::removeRole does not exist or is not callable in this context (in /wire/core/Wire.php line 231)

#0 [internal function]: Wire->__call('removeRole', Array)
#1 /site/modules/FormTemplateProcessor.module(198): Page->removeRole('guest')
#2 [internal function]: FormTemplateProcessor->___savePage(Object(InputfieldForm))
#3 /wire/core/Wire.php(267): call_user_func_array(Array, Array)
#4 /wire/core/Wire.php(229): Wire->runHooks('savePage', Array)
#5 [internal function]: Wire->__call('savePage', Array)
#6 /site/modules/FormTemplateProcessor.module(237): FormTemplateProcessor->savePage(Object(InputfieldForm))
#7 [internal function]: FormTemplateProcessor->___render()
#8 /wire/core/Wire.php(267): call_user_func_array(Array, Array)
#9 /wire/core/Wire.php(229): Wire

After commenting out the following line in the ___savePage() it works and Page gets saved as child of the form page:

$this->contact->removeRole('guest');

I have only tested with standard text, email, textarea fields.

Would be great to may have this developed further. What are the plans on this? This is intended to be for the admin only? Or would it be possible to have clients build a form in this way?

Link to comment
Share on other sites

Thanks I have updated for 2.1 and placed on GitHub:

https://github.com/ryancramerdesign/FormTemplateProcessor

Would be great to may have this developed further. What are the plans on this?

Somewhere around ProcessWire 2.3 we'll be including a formal form builder. Not yet sure if it's going to use the same approach as this one.

This is intended to be for the admin only? Or would it be possible to have clients build a form in this way?

This can be used for public facing forms. But the person creating the forms should be an administrator in PW (whether the developer or the client).

Link to comment
Share on other sites

As always, much appreciated! Already on my watch list. :) I can't wait to see how this evolves.

I think having a way to build simple or even more advanced forms, is a very welcome addition to further speed up the process. "Everybody" hates building forms manually.

EDIT: Oh and new version tested, still works! ;)

Link to comment
Share on other sites

I came across this thread only now. This module would certainly be very useful and i though i could throw something in the discussion.

I would like something like that too, though don't know how it could be done without being something that generates markup.

that one is from January already :)

Symphony as a nice way of dealing with this problem. The System generates the markup, but instead of using it automatically, it just gives it as an example to paste on the template file. Here is the form builder on the admin: http://symphony-cms.com/workspace/assets/learn/09-event-editor-1264826920.png; and here is a usage example: http://symphony-cms.com/learn/tutorials/view/say-hello-to-symphony/6/#pagehead.

I think this is quite a simple way of giving control over the markup.

Link to comment
Share on other sites

Great example, thanks for posting it. There are definitely some things I like about that approach. The only problem is that it's static. You can't go back and make changes directly to the form (without copying and pasting the whole thing, or parts of it again)? And if you've customized the markup further, then copying and pasting may then be out of the picture. Still, seems like a worthwhile compromise and it really may be the best way to go. But I see this approach as being one more aimed at people that already know how to build their own forms and are just using this as a convenience. So this is one area where I'm still leaning towards more automation and less markup control, just to keep things dynamic, and within reach of clients. But providing the copy/paste markup like this seems like a good option to provide regardless.

Link to comment
Share on other sites

  • 1 month later...

Since the module can save entries as pages, would it be usable to create

"web directories" of persons/users/links with description and pictures ?

saving to pages is not different than saving to sbdg, right ?

So the missing parts are

- security options for images

- users creation and setting up their pages.

Ryan (and someone else) do you think that will be possible with the

way you intend to make the formBuilder updated ?

I'm pretty sure there is enought resources on php to get something like that done

(i mean even by me) but i was wondering how hard would that be and how

PW would help do it..

I should read again this topic and the ones about images galery...

Regards,

Link to comment
Share on other sites

Ryan (and someone else) do you think that will be possible with the

way you intend to make the formBuilder updated ?

I see the ability to import data provided by form submissions into pages as pretty important. While it may or may not be in the first preview version of the form builder, it's something that is most definitely part of the overall plan.

Link to comment
Share on other sites

I'm currently using this module to render simple contact form and it works great so far.

Now I got a page reference field with a select inputfield for selecting a category. These categories are pages and they are multilang. So there's 3 fields for title_de, title_en, title_fr. How would it be possible to render the select chosing the option text from the current language?

So far I've added a parameter to the ___render($lang) function and give that to the ___buildForm function where the form is built.  How can I make it (if ie inputfield->name is "category_select") using like "title_$lang" for the option text. Or maybe simpler /alternatively, how can I build the select menu using API?

Any help is appreciated.

EDIT: I should first investigate.. then ask :D I found the simplest solution:

<?php
if($inputfield->name == "formfield_category_select"){
$inputfield->labelFieldName = "title_$lang";	
}

This sets the field chosen from the reference pages for the inputfield select. Amazing, didn't thought it was that simple. :D

EDIT: Only problem now the select has id's as value which get sent by email, how could I set the option value to be the title?

EDIT: Well I think this wouldn't be easy possible, no? Now what I did is a simple check, when preparing the mail content for sending email, for the fieldtype label. If it's the category select, I do a find using the id and return the title_de, title_en ...

Link to comment
Share on other sites

  • 4 weeks later...

Sorry for the double post.

Ryan, I'm using this for simple form. I noticed there's a setting "emailSubject" but on the mail send, you don't enter $this->emailSubject its a hard coded "Web Contact" ...

Also I had to modifiy it a little here and there to make it work for my case (multilang). I also added a property to be abel to add a string before the message body.  I know this is still very rough version, but just to mention.

Link to comment
Share on other sites

  • 3 weeks later...

I've got the form to work fine using the form template processor on one website, but i cant seem to get it to work on another website  ???

When submitting the form, it does not check the validation fields and just returns to the main page(without errors).

I've tried reinstalling the module but no luck.

Any suggestions? :)

Link to comment
Share on other sites

I had something similar a while back - are you sure the fields you've set as required are actually spelled right in both the formbuilder code and the HTML code? If they don't match then they won't get checked - that was my issue anyway.

Link to comment
Share on other sites

my fields are correct, they match the names. It's as if it does not even validate the fields

$form = $modules->get('FormTemplateProcessor'); 
$form->template = $templates->get('contact'); // required
$form->requiredFields = array('form_name','form_email','form_message');
$form->parent = $page; // optional, saves form as page
$form->email = 'jerez@giovanniorigins.com'; // optional, sends form as email
echo $form->render(); // draw form or process submitted form
Link to comment
Share on other sites

Ah, another one I encountered a while back - do you have the relevant styles in your stylesheet for the error messages? I'm not 100% sure you would see them clearly or at all without the CSS.

Link to comment
Share on other sites

Also check that the template you are using with this (contact) doesn't have caching turned on. If you need to use caching with the form, you'll want to specify a POST or GET var that must be present to disable the cache (see the cache settings in the template).

Link to comment
Share on other sites

  • 2 weeks later...

I've got a situation where I've got a "request a callback" type form on every page, and a normal contact form on the contact page for a website.

I noticed that if you re-use fields and don't fill the name out on the Contact form, it displays the errors on BOTH forms. I then changed the fields so they each had their own fields, and then when you submit an empty contact form it correctly displays the errors for the contact form, but the other form is replaced by the "Thanks you, your submission has been sent" message.

So... there are some issues with multiple forms on the same page :( Is there any easy way to tweak the code so that it handles multiple forms correctly? I was thinking the easiest might be to pass the template name as a hidden field and also use it as the ID for the form - that way some checking could be made which then correctly processes only the one form (I'm assuming it processing any forms it finds at present?).

Link to comment
Share on other sites

The FormTemplateProcessor module was always intended to be a proof of concept and not much more than a starting point for people to customize and build from. At present it's not designed to deal with multiple instances of itself (though could easily be updated to). When it looks to see if a form is submitted, it is checking $input->post->submit. If you've got two forms on the same page, then they are both going to be detect that submit. A better solution would be for it to assign a unique variable (or submit button name) that goes with each form so that one can't be confused for another. When we build a proper form builder/processor, we'll definitely be handling all this stuff in the module. But until then I still think it's better to manage your own forms rather than use this module for it (unless the needs are very simple).

Link to comment
Share on other sites

  • 2 weeks later...

Since I haven't gone through this module and its comments, this might be OT:

If you've got two forms on the same page, then they are both going to be detect that submit.

Aren't browser sending only data from form, which has the pressed submit in it? Meaning, if I have form1 with submit1 and form2 with submit2, on submit1 it sends only fields/data from form1 and on submit2 only data from form2?

Link to comment
Share on other sites

That's correct, and that would be the simple fix in this case. :) But because this particular module isn't singular (i.e. a new instance is created whenever you load the module) it would have to keep track of how many instances of it are running (via a static variable in the class).

Link to comment
Share on other sites

  • 1 month later...

That's correct, and that would be the simple fix in this case. :) But because this particular module isn't singular (i.e. a new instance is created whenever you load the module) it would have to keep track of how many instances of it are running (via a static variable in the class).

Just saw this and tho i know it's a big deal, my friend and i recently did this on a multiple form page, with potentially the same 'instances' of the form and we incorporated a sorta 'nonce/hash' based on the instance of the 'form' itself. works DANDY too!

it's not a biggie but could be an easy add. (course, i say easy but you get me)

in that way you could also do ajax submits as well.

just sayin'.

Link to comment
Share on other sites

I don't suppose you'd be able to share the code would you Bill? No problem if not as I could probably work it out myself next time I need it, but no point everyone doing the same thing either ;)

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