Symfony2 get search via forms and links - forms

In Symfony 2 I tried to create a little search engine. The search consists of a form and some links (like facets on solr). I managed to set up the search form with form binding, creating special searchobject class in entitiess and all this via form post request. For purpose of saving previous searches I saved the complete search object in session serialized.
My question(s) would be:
How to use get requests with a form without outputting form name? Is using forms via get valid in Symfony 2? What is the best practice?
Many sites made with Symfony 2 I see are using www.url.com/search?q=thequery&param2=xxx.
If it's valid, how would I prefill the form? Are there some examples to look at?
(PS: if using the form the way it works now, the url stays the same eg. www.url.com/seach)

Just try to change you html form declaration to specify method="GET".
And that's all, you can create your form as usual. :)

Related

differentiation between form and upload Form in grails

I am little bit new to grails and I don't know the difference between form and uploadForm in grails, and if use upload form I can able send attachment file to grails controller. But not able to send attachment file when using form.Someone explain the difference of those form types.
One of the best places to look is the documentation for both of these (form and uploadForm).
As stated in the documentation regarding uploadForm:
Identical to the standard form tag except that it sets the enctype
attribute to "multipart/form-data" automatically.

Joomla Contact Form (from the ground up)

I'm looking to create a customized contact form in a Joomla 3 site I have created. I know how to write the php code for the form, but I'm unsure of where to place the code.
Ok, the form is located at http://www.theoscorner.com/contact-us. What you see there is only the design, and there is currently no script for the form to submit to. If I wanted to create a new php page for the form to submit to, what is the best method of doing this? For example:
Should I create a completely new php file where the template's index.php file sits, and use a module (instead of an article) to hold the form.
Should I create a new article page, and place my php script in that article?
Should I hard-code my form into a module, and place a php function at the end of the index.php page which gets called when the page is refreshed and the POST values are set.
I'm just looking for any type of guidance I can get right now. I don't want to use a third-party plugin, because I want a little more control than they allow. Thank you for your time.
Just use RS Forms or Contact Enhanced, they are both Joomla extensions available on extensions.joomla.org
There is no need to create your own MVC component.

Dynamic show fields Symfony2

I trying to add some fields to form depending of checkbox. But I have no idea how can I do that. I think Ajax can be useful, but I dont work with Ajax in Symfony2 yet, and if my form build up not in the controller what value I need specify in url: option of Ajax?
That's quite a broad question, but essentially: the Symfony way is to add them to the Form in the Controller by reacting to FormEvents.
Symfony Docs on Form Events
One way to achieve what you're after is to submit the form twice - the first time code will react to the checked checkbox and arrange the rest of the form as required, the second time the form will be valid and you can take action. Details on the above link. AJAX might help with this, allowing a form submission as soon as you've checked the checkbox.
Although you can create HTML form fields using AJAX, when you submit the form those fields need to exist in the Form object. You can add them just in time, in the controller, before Symfony tries to bind them.

Disable form validation on empty forms with Play Framework

I'm pretty new to Play Framework.
My problem is that when a user clicks on the register link, he will instantly see validation errors.
The problem is that the method that serves the form also validates the form. So when the user clicks on the register link, gets to the validation without any input and then gets validation errors.
One solution would be to have an extra method to only serve the register form. But this would require an extra form and an extra route.
Another solution would be to disable validation on empty forms.
Is this possible? If not is there an other way?
You are on the way to a good solution. Make a second method.
GET /register controllers.RegistrationController.showRegistration()
POST /register controllers.RegistrationController.register()
The first is to display the registration page with the form, the latter to handle the form submit.
A method should stick to do one thing: either to show a registration page or to handle a post. Generally it's not a good idea to write a single method with a lots of if-then-else flow control statements.
Play framework also supports REST principles: in a simplified way GET is to retrieve a resource (=an empty registration page here), POST is to submit data(=do the registration).
Have a good look at Play framework's examples, I think the computer-database is very simple and a good starting point for you.

Standalone Wordpress form does not post to specified action when fields are populated

So this is weird....
I have a form I've created myself (not a plugin, this is what I mean by standalone), and for some strange reason it does not post to the form's action when the form fields have data in them. However, when the fields are empty it successfully posts to the other page.
I have turned off all validators and really am not sure why this is happening.
Do I need to hook into a Wordpress function to allow for my own form submission?
I realized my permalink structure is /%category%/%postname%/ so perhaps it cannot properly post to the URL since it's not an actual file.
How can I achieve this?
Thanks
Wordpress uses query vars to route the request to posts/pages etc. My guess is that one/some of your field names are used by Wordpress internally.
Check http://codex.wordpress.org/WordPress_Query_Vars for the list of vars you shouldn't use