Should I generate html form? - forms

I'm building a php application that will have many modules/plugins. The issue is that creating smarty template for form's of each plugin and writing validation code for each looks redundant and at the same time using PHP to generate form will restrict the flexibility in controlling each form's layout structure the way I would have wanted.

Using PHP classes and inheritance you can write the validation and layout code once and overriding them whenever you need specific behaviour.

Related

CMSMS FormBuilder submit call custom function

I am using CMS Made Simple for my website.
I have some custom PHP code which I would like to call when a users clicks submit on my Form Builder form.
I know my code is now working correctly, but I cannot seem to find where in the FormBuilder code that I can call the function.
I have had a look through the code in the modules directory but I cannot seem to find where I need to put the code.
Preferably I would like to only use this code on certain forms, but if I have to implement for all forms then so be it.
FormBuilder has a field to call UDTs. In the Fast field adder dropdown choose *Call A User Defined Tag With the Form Results" You may have to use Advanced mode
There is also the UDT integration tab.

Adding attributes to cq5 form using FormsHelper

I'm trying to add an attribute to the form tag of a cq5 form. I noticed that the output is generated using
FormsHelper.startForm(slingRequest, new JspSlingHttpServletResponseWrapper(pageContext));
I was curious how I can either:
alter the request so that the formHelper prints the form w/ the attributes I need
Hook into the actual print out to include the attributes I need.
Any help or direction would be good.
note:
I've already checkout out the javadoc for formshelper, done some searching via goolgle, and dev.day.com including the dev.day.com doc on developing forms.
thank you
API doesn't allow you to add any attributes to this tag. You can only specify desired CSS classes adding css property to the form component. Of course, you can also create component sling filter and response wrapper to rewrite created form, but it seems to be an overkill. I think better solution is using JS to add attributes client-side.

Spring form field id with dot doesn't work well with jquery

When I build a form I need to use a dots in path variable. When html is generated inputs has dots in ids. There is a problem with third party jquery plugins like validators. They doesn't work well with dots. Is there a way to change all dots into eg. "_".
One solution would be not to use automatic form binding, so instead of using <spring:form/> you might still use plain HTML tag <form> and handle it regular way. It all depends if you want to benefit from Spring's mechanisms like automatic form field binding and error handling. But if you are handling form validation with JavaScript and you plan to do it across the whole project, you might want to make that effort. What I usually do is to handle client side and server side validation with JavaScript (plain and AJAX), so I'm not using <spring:form/> at all.

form decorators in zend framework

I am new to zend framework. I have used zend form and decorators to make form using class and decorators. The form i created was simple register form.
Now my question is "Is it advisable to use zend form for many complex forms as well ?" i have made many complex forms full of jquery with lots of conditions.. so at this moment i feel that it will very much difficult to make such form using decorators.
The power of form is zend filters and zend validartios which saves our hell lot of time...
So can we make forms in our phtml files and still use the power of filters and validators or is dere any other way...???
Well, my opinion would be to try to make the forms using Zend Form. The reason is that time spent on making Zend_Forms, setting up decorators, customizing elements or creating your own elements will be saved once the form is in use. With Zend Form you get very easy and straightforward way of validating your form, filtering contents of your fields, managing error messages, translating it, etc. In addition, once you spent time on e.g. writing your own or customizing existing decorators, form view helpers, form elements, it will be quite easy just to take them and use them in your next ZF project.
So in my opinion, in the long term using Zend_Form will save you time, even if at the beginning it may seem that using Zend_Form causes more troubles and headaches than not using them.
But off course, if you want to make your forms directly in phtml there is nothing that stops you. Both Zend filters and validators can be used on their own, independently of Zend_Form. You could also create zend form that has the same elements and structure as your "phtml form". This way you could only populate the zend_form, and use it only for validation and filtering of submmited data, not for actual rendering of your form.

Why do we use HTML helper in ASP.NET MVC?

Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project?
When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper.
Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML.
If I use an HTML helper I lose the speed. When I use HTML I just type and of course I am not aware of it. But using helper, it is hard to understand.
What thing do we get when I use HTML helper? I think it is nothing I get because I lose the speeed. Others can't understand what I do using helper and can't customize the code if they want.
Why do we use HTML helpers?
You use HTML helpers to encapsulate some small HTML fragments which are repeated all over your pages. And to avoid writing those HTML snippets all over again you use helpers.
They are very useful, especially when dealing with things like URLs because instead of hardcoding your links helpers take advantage of routing the definition on your server and by simply changing those routes the whole site URLs' change without ever touching any single HTML page.
Another scenario where HTML helpers are useful is for generating form input fields. In this case they automatically could handle values when posting back and show associated validation messages. Can you imagine the spaghetti code you would have to write in your views if there weren't HTML helpers?
The biggest advantage I find is with the editor and display templates.
If your editor for a field is more than just a simple input box, you can put that into a template and replace the several tags with a call to
<%:Html.EditorFor(m=>m.Property)%>
This means that your page is a lot easier to edit as you aren't wading through a lot of fluff HTML to find what you want.