Jump to content

Forms into Page Field


Raul
 Share

Recommended Posts

Hello, 

I'm using Formbuilder in a project.

And now I have to build a system to manage forms.

The system is not simple because there are pages that contain various forms at same time. I try to explain it:

There is a page that contains variuos forms.

Each form has an area where the admin can add text fields.

The formbuilder doesn't allow this text-area but I had an idea to do it.


The page uses a template "foms-container" and contains

Template "forms-container" contains
- Headline (textfield)
- Description (textarea)
- "Field Page" restricted to pages with template "form-page" configured as multiple-array

Template "form-page" contains
 - Repeater with 2 textfields
 - "Field Page" restircted to Forms made with Formbuilder

And my problem is that the "Field Page" can't be restricted to Forms only to pages.

Is there any form to do it?

Can I do it with php.

Thanks in advance.

Raul

Link to comment
Share on other sites

And my problem is that the "Field Page" can't be restricted to Forms only to pages.

I'm not sure that I follow exactly what you are trying to do. But one thing to keep in mind is that a Page can literally be mapped to anything. So while your form field may involve a page selection, you could then say "this page maps to this form" and "that page maps to that form". You could even make the template for that page load a specific form.

In Form Builder, you can also specify defined lists of selectable items outside of Pages. So you might just enter each of your selectable items to be the same as the name of a form. 

Link to comment
Share on other sites

Hello Ryan, 

Thank you for your response. I try to clarify.

In processwire exists the "Page" field that allow to create a reference to a page.

I need the same but the reference must be to a form.

Why?
 

In the admin area the editor can create forms (with Fombuilder) and these forms have various description fields.

My idea was to create a template with this fields and one field "Forms" that references a form.

Yes, I could create pages with the same form name and use the "embed" function of forms but the customer wants diferent names for forms and pages. Moreover the forms aren't created for the same person that creates the page, so this person doesn't know the form name.

I have used the extension "FieldtypeTemplates" and I have change it to use it with multiple forms (FildtypeForms.module). It runs but i want select only one form.

I have changed the inputfield from InputfieldAsmSelect to InputfieldSelect (FieldtypeForm.module) but the selected value ist not saved and I don't be sure why.

I have uploaded the changed files and a file in PDF with the schema. I hope this can help to understand the situation.

Thank you in advance.

Raul

FieldtypeForms.module

FieldtypeForm.module

forms_schema.pdf

Link to comment
Share on other sites

I think the problem here has to do with the validation/sanitization functions. Most likely the values are coming through as strings (since they come from a user input form) and your code is throwing them out since they don't match is_int(). In FieldtypeForm.module:

  • Make your getBlankValue() function return a blank string (or 0 if you prefer), rather than an array. 
  • In sanitizeValue, typecast $value to an integer, like $value=(int)$value; if(!$value) return null; Then get rid of the is_int($value). Values coming through forms may be strings rather than integers, so using is_int() to throw out a value can basically break the whole thing. 
  • Change your wakeupValue() and sleepValue() functions to do nothing more than: return (int) $value; 
  • In your getInputfield() function, you don't need to set a 'name' attribute, as PW already does this for you. 

If it still doesn't work after the above changes, review /wire/modules/Fieldtype/FieldtypeInteger.module, as it has identical storage needs as your module. 

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...