Jump to content

Module want: form builder


apeisa

Recommended Posts

Hi,

installed and templating as in readme - work perfect. thanks!

But there is a little style-error in included CSS!

When a field is empty, then should be the error-message in red (or what you want), but the class is wrong (PW 2.3).

So change the css from:

.ui-state-error-text {
	color: red;
}

to:

.ui-state-error {
	color: red;
}

as you see without '-text' at the end of class.

Link to comment
Share on other sites

  • 2 months later...

Just before: $mypage->save(); which I mention a couple of posts above, you just need to add:

$mypage->removeStatus(Page::statusUnpublished);

EDIT: although I thought they were published by default and you actually had to add:

$mypage->addStatus(Page::statusUnpublished);

to set them to be unpublished.

Edited by adrian
  • Like 1
Link to comment
Share on other sites

I did this but I got error.........

$form = $modules->get('FormTemplateProcessor'); 

$form->template = $templates->get('reply'); // required

$form->parent = $page; // optional, saves form as page

$form->removeStatus(Page::statusUnpublished); //on this line I got error

echo $form->render();

Link to comment
Share on other sites

Oh, I see - you are actually using Ryan's module from the first page of this thread - sorry, my bad! I assumed you were using diogo's code.

There is a line in that module:

$this->contact->status = Page::statusUnpublished;

The easy hackish option would be to remove that line from the module code.

  • Like 1
Link to comment
Share on other sites

Thanks I did this but I want it to be dynamic. Is there any way to change the module to set this dynamically. Like...............

$form->publish = true/false

I guess so. What boolean condition/logic do you want to check for?

Link to comment
Share on other sites

I don't think Ryan has that option in the module. The module code could be enhanced to handle that, or you could do something like this after rendering your form.

$newpage = $page->children->last();
$newpage->removeStatus(Page::statusUnpublished);
$newpage->save();
 

I think this should work.

EDIT: added the necessary save line at the end.

EDIT #2: Actually not sure if this will work at all - this could get messy if the form is rendered and not submitted and if someone else submits while another form is still being filled out. Sorry, might need to rethink this and go with editing the module code properly.

Ignore all the above and see http://processwire.com/talk/topic/59-module-want-form-builder/?p=41431

Edited by adrian
Link to comment
Share on other sites

It might be best to go with something like:

$form->pagestatus = 'unpublished';

That way the module could simply grab "pagestatus" and add it to the page using addstatus before saving. I'll see if I can find a few minutes to modify the module to handle this.

Link to comment
Share on other sites

I hv change the module............and it works ............ It needs three steps

Line No:                Add  this

90                           $this->set('publish', false);

110                          else if($key == 'publish' && $value) {

            if($value!=0&&$value!=1) throw new WireException('$page->publish value should be true or false');
            $this->publish = $value;
        
        }
 
210                               
if(!$this->publish)
            $this->contact->status = Page::statusUnpublished; 
 
 
 
 
and in your code just add   $form->publish = true;    and done.
 
  • Like 1
Link to comment
Share on other sites

Here is a revised version of the module.

It accepts all Page::status options, eg.

$form->pagestatus = Page::statusUnpublished;

$form->pagestatus = Page::statusHidden;

If left blank, then the page will be published. Not sure if this is really an ideal default. Maybe it would be good to get some input from others on this.

FormTemplateProcessor.module

Edited by adrian
  • Like 3
Link to comment
Share on other sites

That error messages sounds like you are trying to use a file or image field with FormTemplateProcessor, and file/image fields aren't supported with it. The error message should go away if you remove the file/image field. 

Link to comment
Share on other sites

  • 4 weeks later...

Yes, there should be a placeholder option for any text-based field in ProcessWire. You'll see it when configuring it. To use it from the API side, you'd do:

$inputfield->attr('placeholder', 'your placeholder text'); 
  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hello,

I'm using latest version of this module with PW 2.3 and it's working fine so far.

But when in debug mode, it throws 2 notices/warnings:

Notice: Trying to get property of non-object in .../wire/core/Page.php on line 275

Warning: Invalid argument supplied for foreach() in .../wire/core/Page.php on line 275

My form has no fancy fields and is sending the input to an email.

There's one select field for a salutation (Mr., Mrs...). In the message that gets sent, the option values are put out instead of the option name. How can I change that?

Cheers

gerhard

Link to comment
Share on other sites

  • 3 months later...

Hi,

for all german users of this FormTemplateProcessor.modul who want to get german Umlaute like öäüß and not found the issues to similar slovak characters on github.

After you have checked all the other solutions of that problem, like to save the page where the form is in "utf-8 without bom" and set the right header of the page, then only one is to do:

search in /site/modules/FormTemplateProcessor.module for

$value = htmlentities($this->contact->get($field->name));

and change to:

$value = htmlentities($this->contact->get($field->name), ENT_QUOTES, 'UTF-8');

This was the solution for me.

(Lösung für deutsche Umlaute im Kontaktformular)

Thanks for this fine modul, ryan!

_guenter_

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Here is a revised version of the module.

It accepts all Page::status options, eg.

$form->pagestatus = Page::statusUnpublished;

$form->pagestatus = Page::statusHidden;

If left blank, then the page will be published. Not sure if this is really an ideal default. Maybe it would be good to get some input from others on this.

since this is working great in 2.4.11 too it should be a pullrequest on github?

Great module - really easy to work and get the idea for forms with PW.

Is there a threat/topic (i'd searched) for multistep forms? Or a hint to get on the right path?

kind regards mr-fan

Link to comment
Share on other sites

  • 3 weeks later...

I've getting a contact form working nicly with this great module. (FormTemplateProcessor)

So only one question stays:

What is the best way to build in something like a honeypot?

-> Can i simply append a field or could i setup a kinda hidden field on the used pagetemplate?

-> How could i build in the check against that field?

-> Have i work with a hook for the check?

Unlikely my skill are limited to learn the API for pagetemplate files and simple backend tweaks, but not to get the idea where to start here.

The contactform itself works great  - frontend looks good - forms send via mail and saved as pages under the contact page itself.....

regards mr-fan

Link to comment
Share on other sites

Thank you i've digging through it.....

so far i wanna use the FormTemplateProcessor.module i've to change it.

Hard knocks for a php hobbyist (for tha label scriptkiddy i'am to old ;) )

i've changed some simple points/steps:

1. added a textfield (namend "spam") to the contact-template.php

2. added array setting for fields to check:

// Array of field names that should be used as honeypot when drawing the form
$this->set('honeyFields', array('spam'));

3. Check if the $this->honeyfields has content

This is the part where i'am not shure where to put the check.

Tomorrow i will try some things out......

/**
 * Render a form or process it's input
 *
 * @return string Output of the form or success message upon completion.
 *
 */
public function ___render() {

	if(!$this->contact->template) throw new WireException("You must specify a Template");

	$form = $this->buildForm();

	// if the form hasn't been submitted, then just return the rendered form.
	if(!$this->input->post->submit) return $form->render();

	// variable to hold our output, which we will return
	$out = '';

	// now we assume the form has been submitted.
	// tell the form to process input frmo the post vars.
	$form->processInput($this->input->post);

	// see if any errors occurred
	if(count($form->getErrors())) {
		// re-render the form, it will include the error messages
		$out .= $form->render();

	} else {
		// successful form submission, so populate the new page with the new values.
		foreach($form as $field) {
			$this->contact->set($field->name, $field->value);
		}

		if($this->email) $this->sendEmail($form);
		if($this->parent) $this->savePage($form);

		$out .= $this->successMessage;

	}

	return $out;
	}
}
Link to comment
Share on other sites

You can easily make the module your own and add or change things. This would be totally the way to go here I think. I think Ryan don't really have plans to go on with the module and was more an simple example how to build a simple form using a template.

--- With hooks if interested read on (little tricky to get it done) ---

Removed code. Screw it :) , it won't work cause how the module is built. It won't allow to easily hook the form processing that happens in the ___render(). It's better after all to either change the module to your needs or add honeypot support and do a pull request maybe.

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