Add partial form with jsf and primefaces [duplicate] - forms

I am using the Facelet Templating Technology to layout my page in a JSF 2 app that I am working on.
In my header.xhtml, primefaces requires that menubar be enclosed in h:form.
<h:form>
<p:menubar autoSubmenuDisplay="true">
Menu Items here!
</p:menubar>
</h:form>
So, in my contents pages, I will have another h:form or more.
Will it just work if I just place the h:form in my template.xhtml?
<h:body>
<h:form>
<div id="top">
<ui:insert name="header"><ui:include src="sections/header.xhtml"/></ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="sidebar"><ui:include src="sections/sidebar.xhtml"/></ui:insert>
</div>
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
<div id="bottom">
<ui:insert name="footer"><ui:include src="sections/footer.xhtml"/></ui:insert>
</div>
<h:form>
</h:body>
I am actually thinking of a use case where I need multiple h:form in a page.
Thanks

You can safely use multiple forms in a JSF page. It's not different than when using plain HTML.
Nesting <form> elements is invalid in HTML. Since JSF just generates a bunch of HTML, it's not different in JSF. Nesting <h:form> is therefore also invalid in JSF.
<h:form>
...
<h:form> <!-- This is INVALID! -->
...
</h:form>
...
</h:form>
The browser behavior as to submitting a nested form is unspecified. It may or may not work the way you expect. It may for instance just refresh the page without invoking the bean action method. Even if you move the nested form (or a component that contains it) outside of the parent form with dom manipulation (or by e.g. using the PrimeFaces appendTo="#(body)"), it still won't work and there should be no nested forms at time of loading the page.
As to which forms you need to keep, having a single "god" <h:form> is actually a poor practice. So, you'd best remove the outer <h:form> from the master template and let the header, sidebar, content etc sections each define its own <h:form>. Multiple parallel forms is valid.
<h:form>
...
</h:form>
<h:form> <!-- This is valid. -->
...
</h:form>
Each form must have one clear responsibility. E.g. a login form, a search form, the main form, the dialog form, etc. You don't want to unnecessarily process all other forms/inputs, when you submit a certain form.
Note thus that when you submit a certain form, other forms are NOT processed. So, if you intend to process an input of another form anyway, then you've a design problem. Either put it in the same form or throw in some ugly JavaScript hacks to copy the needed information into a hidden field of the form containing the submit button.
Within a certain form, you can however use ajax to limit the processing of the inputs to a smaller subset. E.g. <f:ajax execute="#this"> will process (submit/convert/validate/invoke) only the current component and not others within the same form. This is usually to be used in use cases wherein other inputs within the same form need to be dynamically filled/rendered/toggled, e.g. dependent dropdown menus, autocomplete lists, selection tables, etc.
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated - point 2
What is <f:ajax execute="#all"> really supposed to do? It POSTs only the enclosing form
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
<p:commandbutton> action doesn't work inside <p:dialog>

I was confounded by this issue for a while. Instead of a series of independent forms, I converted to a template, that is, rather than making a call to a xhtml with listed forms, usually as ui:include, I make a call to those formerly ui:included xhtml pages that ui:content captured in a parent template.

Related

How include a custom form to be render in a Modal

Hello I'm trying to include in a modal a custom form (is not a BizKentico Form) when it is rendered the tag <form> is missing and when click submit buttom it realod the page and lose de input data before.
Are you using Portal engine or MVC?
If you are using Portal, Kentico wraps the entire page in a form tag. You can hack it buy doing something like this, but it may cause some issues on the page.
</form>
<form>
your form data
</form>
<form>

Issue with CSS; captcha overflowing form boundaries

I'm working on a website redesign based on the Bootstrap 3 framework.
In configuring the site's contact form, and implementing a captcha, I've run into an issue with my CSS.
Everything works well in Chrome, but in Firefox, the captcha overflows the form boundaries, and is off to the side, whereas in Chrome, it's under the form and integrated more normally. To attempt to fix this, I put the captcha (which was outside of the form's div tags originally) inside it's own div group. That fixed part of the issue, in properly aligning the captcha under the rest of the form.
However, now that I've done that, the captcha (and the form label it's associated with) overruns the form boundaries on both sides, and doesn't display properly in either Chrome or Firefox. Further, it doesn't space properly, despite being in its own div.
http://www.weatherworks.com/contact/contact.php
I'm not sure how - or if - I can fix this. I'm a student and web design is more of a hobby for me; I'm actually doing this redesign as part of a weather-related internship. I'm fairly knowledgeable on HTML and CSS, but am pretty lost with this issue. Was hoping someone here who's worked with forms and/or Bootstrap might have some insight for me.
Thanks!
You missed a closing tag of the <div class="form-group" id="commentTxt">. Place a close tag above the next <div class="form-group">
<div class="form-group" id="commentTxt">
.
.
.
</div> <!-- Add this div -->
<div class="form-group">
<label class="col-lg-2 control-label">Verify Humanity</label>

How to create a simple html form in symfony2 without using formbuilder

I have a (hopefully) simple problem:
I want to use a simple html form in a sympony2 project. The Problem is, that noting is sent by get through the form.
The Url after sending the form is: localhost:8888/de/search_art?
you see... there is no string after the ? !!!
The form looks like this:
<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
<input type="text">
<button type="submit" class="btn btn-default">Send</button>
</form>
This is my routing:
func_search_art:
path: /search_art/
defaults: { _controller: FuncSearchBundle:Search:SearchArt }
I don't want to do something within a controller for it, because it is in the navbar and for this it has to appear in every page. I don't want to initialize a form variable in every controller of the page for a simple navbar search field.
Is there a possiblity to create a simple form like this in symfony2 without using a form builder and so on ... ?
Greetz Michael
Yes, you can safely keep your form written in twig in the form you presented it. No need to create a form builder in every controller and send the form to twig. The only place you will have to build it is the SearchArtAction method from SearchController, where you have the handling functionality for this form.
Also you need to give a name to your text input.
<form class="navbar-form" role="search" method="get" action="{{ path('func_search_art') }}">
<input type="text" name="q">
<button type="submit" class="btn btn-default">Send</button>
</form>
Because your input lacks the name attribute , which is the relevant attribute to create the post data/query string.
You can't it will give you: "The CSRF token is invalid. Please try to resubmit the form". Regardless of that it actually work without it. For some reason Symfony serialized the forms. I particularly hate the fact that I need the form object to use forms, in many cases I found it overkill. Your $form->isValid will also failed, but the $form->isSubmitted() will not. One of the reasons I hate the form object is how tedious it is to populate a drop down with an EntityType, instead of making simple symfony manage to make the process a damn nightmare.

Form Variables are not showing up after form submit. ColdFusion

<form name="abc" id="abc" method="post" action="/test.cfm" enctype="multipart/form-data">
<input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>
for some reason when I hit submit the "btnSubmit" is not showing up in the cfdump.
<cfdump var="#form#">
There aren't a lot of things that could cause it to simply not appear in your form. My short-list of culprits are:
Looking at the wrong file / server.
The page is being redirected via cflocation or otherwise (javascript location.replace() or location.href=x) -- this would cause that problem even if the redirection is returning the browser to the same page.
Form variables being stripped out somewhere further up, I would guess in onRequestStart
A local variable named "variables.form" was created and set to a structure further up - not very likely, but I suppose it's possible someone could accidentally write something like <cfset form = url />, which might cause that
Usually, when something like this has happened to me in the past, I've found that I've been viewing the wrong file in the browser. Usually it's come down to me looking at the same file on the wrong domain name, e.g. looking at the production server instead of the development server.
If you combine your code segments above into a single file like this (test.cfm):
<cfdump var="#form#" />
<form name="abc" id="abc" method="post" action="test.cfm" enctype="multipart/form-data">
<input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>
That ought to give you some insight into your problem. Note that I removed the leading-slash / in the form action, so that this form will post to itself. When I first view this template, I see an empty struct (followed by the button), because I haven't put anything in the form scope yet. When I submit the form I then see two elements in the structure, fieldnames and btnSubmit. That's another good indicator, if you don't see fieldnames in the form structure, then your CFML page may not have received a form submission. If you know you're looking at the right page and you've submitted the form and you still don't have the fieldnames entry, then I'd start looking for potential browser redirection.
You might also want to add an empty Application.cfc in the same directory just to be sure that there's not an application interfering with it. It's possible that something in the onRequestStart might be stripping out form variables with the name "btnSubmit" or even any form variable with the string "submit" anywhere in the name. I wouldn't expect it though -- I'd look for other causes like cflocation tags first.

Are form elements outside of a FORM tag semantic html5?

If I have a SELECT tag that will filter a table based on a user choice, does the SELECT tag need to be in a FORM tag (to be valid HTML5), if the resulting functionality will not work if JS disabled (i.e. we'll show the entire table or a 'more' link instead of doing a server-side filter on select of the form action/submit option (We may write the select in JS so it disappears from the markup if JS disabled.
Or do all form elements need to be in a form tag regardless of usage (and therefore a null 'action' attribute value).
I know HTML5 allows almost anything, I just couldn't find a definitive answer on W3, so thought I'd get your thoughts. Hope that makes sense.
Cheers.
All the form controls can be used anywhere where phrasing content is expected, which means they can appear just about anywhere in the body of the document. If you don't need to have them submitted back to a server then there's no need for them to be associated with a form, however I've noticed that in some browsers you can't take advantage of the form validation features unless the elements can potentially be submitted.
One feature new to HTML5 is that form controls no longer need to be the direct child of a form element in order to be submitted with that form, the form attribute allows you to specify the id of the form the element should be submitted with.
It would appear that in HTML5 form elements can be outside of a <form> tag and still be valid;
<!DOCTYPE html>
<html>
<head>
<title>Just making this valid</title>
</head>
<body>
<select>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</body>
</html>
The above code validates successfully (minus the obvious character encoding errors).
I haven't read the entire HTML5 Spec, however the validator is usually correct on these sorts of matters.
The HTML5 spec specifically allows <input>s (and other form-associated elements) not to have a <form>:
A form-associated element can have a relationship with a <form> element, which is called the element’s form owner. If a form-associated element is not associated with a <form> element, its form owner is said to be null.
So feel free to use them wherever your heart desires!