Best way of adding additional values to form get url - forms

I was wondering, which is the best way to add additional values to an url created by a form with a GET method... the url looks something like
http://testing.com/results?search_query=landscape&search_filter[]=mountain
I'll have on the results page additional filters and paging system, and I was wondering which is the best way of adding the values of those once chosen/selected to the url? So if clicked on next button it will add a &page=X to the url or/and a &sort_by=top_rate

You can use checkboxes:
<input type="checkbox" name="search_filter[]" value="mountain" />
<input type="checkbox" name="search_filter[]" value="landscape" />
or multiselect:
<select multiple="multiple" name="search_filter[]">
<option value="landscape">Landscape</option>
<option value="mountain">Mountain</option>
</select>

I'm not entirely sure I get the question, but I think the location object may be of help.
Try location.href and then changing it. The browser will change to that new url. So you could get the current, then add your stuff, setting that appended version back into location.href. I think this is what you want, as long as you want the user's browser to navigate to that page.
There is a modern method that allows you to just modify the address bar and title without refreshing/navigating away, using window.history.
http://www.w3.org/TR/html5-author/history.html#history-0
Specifically you might be interested in window.history.pushState. This will let their back buttons work too. :)
Hope this was more along the lines you were looking for!

You need to read your URL in the action script.
Check if the URL has any parameter.
If the URL has some parameters, then append at the end: &newPARAM=newVALUE (you can add as many as you wish).
If the URL has no parameters, then append to the end: ?newPARAM=newValue

Related

form action, blank or period?

I wonder the difference between:
<form method="post" action="">
and
<form method="post" action=".">
I have read this interesting thread. It looks like blank action is handled by all browsers. Some say the period is not a good idea but they don't say why.
Furthermore, this thread is quite old now so i think it would be useful to have an update on the subject.
Thanks.
The blank represents that the result display of the form will display within the same page. Let say if you input the name, address, tel # etc.... and press the submit button. The collected information will display within the same page (probably below the form). I usually do this when i design a form to make sure it works. But there are various reason why they leave it blank instead putting another target page.

Hyperlinks in FOSUserBundle form label

So I've searched, googled, asked and even consulted the stars, but I haven't been able to find a solution to this specific problem.
When overriding an FOSUserBundle form,(specifically the Change Password form, but generally any other FOSUserBundle form), is there a way to set part of the field label to be a hyperlink?
Does the question make sense? I could elaborate if it doesn't.
The goal
I would like to have resultant HTML to look like this:
<div>
<label for="fos_user_resetting_form_has_acceptedtos">I agree to the <a href='/tos/'>Terms Of Service</a>.</label>
<input id="fos_user_resetting_form_has_acceptedtos" type="checkbox" value="1" name="fos_user_resetting_form[has_acceptedtos]">
</div>
What I've tried. . .
I have added the has_acceptedtos field to the User.php Entity and hooked into the controller, as per the instructions. And I have customized the field labels successfully.
Unfortunately, the following syntax, unsurprisingly, doesn't work either:
# app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml
# ...
# Password change
change_password:
submit: Change password
has_acceptedtos: I agree to the <a href='/tos'>Terms Of Service</a>.
...
I have even attempted to override the template, in an attempt to artificially create a label that would appear in the vicinity of the checkbox via css. Didn't work out too well.
Other than re-writing the entire FOSUserBundle to generate my own forms, can this even be accomplished?
Thanks in advance for any suggestions!
You'll have to use a combination of custom form theming and the Twig "raw" method to accomplish this.
Here's an answer that deals with a quite similar issue.

Form Entry, Review then Update

I'm creating a form where the user will enter data, then click "Review" to see the data they entered. Then after review, "Save" the record.
I'm using a <cfform> to submit the form but wonder how to submit the data to the database from the "Review" page since there's no form here.
Should I set variables like FORM.Name = VARIABLES.Name to display on the review page, then convert them back after they submit the "Save"?
Not really sure what to do here. Overthinking?
Just keep in form scope. Basic output of form values, using baked in form.fieldList:
<cfloop list="#form.fieldList#" item="fieldName">
<cfoutput>
#fieldName#: #form[fieldName]#<br>
<input type="hidden" name="#fieldName#" value="#form[fieldName]#">
</cfoutput>
</cfloop>
Link to original form or submit to page where you save it, using values from hidden fields (which should mirror original form values)
A few other ways you could do this, but this seems simplest to me.
Why not using a second form with hidden input fields for the review page? Confirm would be a submit button to the page that saves the data to the server.
Second possibility (not that proper): save the data directly into the database and load it for the review from there. Trick: use a flag with "confirmed" and set it if confirmed. Bad part about that: you have to clean up older data that has not been confirmed.
Improving on Billy Cravens answer. This protects against the fields having Embedded Attacks
<cfoutput>
#lcase(fieldName)#: #xmlFormat(form[fieldName])#<br>
<input type="hidden" name="#fieldName#" value="#xmlFormat(form[fieldName])#" />
</cfoutput>
Also this will not work for image uploads. The lcase(fieldName) is to keeps the fields from being displayed as all caps. Lowercase is often easier to read.

Prevent browser waring when you hit the 'go back' button after form submit

I have a little problem here. Actually, more of an annoyance.
I have a form on my index page that has a small search form:
<form action="search.php" method="post">
<input name="search" type="text" />
<input type="submit" name="submit">
now on the search.php file I just use the $_POST['search'] to retrieve the value that I'm searching. This file also displays the actual search results, which I can click on to go to that page.The search is actual done on the database. Also, because my search returns the top 10 random results from the DB, if I hit the 'back' button and confirm the warning, the search will be executed again, and will return a different set of results.
The problem, as you know, is that when you click on one of the search results and then hit 'back' on the browser, you get that browser warning about 'To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.'.
What's the easiest way to prevent this from happening? I looked into that PRG technique but I'm not sure how to implement that.
Any help would be great.
Thanks.
Bruno.
Is it OK to use GET method here, users won't see warning if form sent by GET method.

How can I post a form and show the result on the same page with Play framework?

I've been playing around with Play framework for a few days, and it seems really cool. However, I ran into some problems when I wanted to have a form on a page, post the form and show the results on the same page (with the form still on the page). Does anybody know if this is possible with Play, and if so: how?
EDIT:
I should have explained better. The form is a search-style form not a save-style form. I want to be able to search for something, have the results come up under the form and still have the values the user filled in in the form (as it is if you type in something that don't validate. I have tried to set values on the params object directly in the search action, but it disappears when the search action calls the new action.
Second try of an answer untested, hope this fits to your problem.
public static void search(String criteria1, String criteria2) {
....
params.flash();
}
search.gsp
<p id="criteria1-field">
<label for="criteria1">&{'criteria1'}</label>
<input type="text" name="criteria1" id="criteria1" value="${flash.criteria1}" />
</p>
<p id="criteria2-field">
<label for="criteria2">&{'criteria2'}</label>
<input type="text" name="criteria2" id="criteria2" value="${flash.criteria2}" />
</p>
Well this is quite simple. You put into the routes.conf a
GET /myPageWithForm MyController.read
POST /myPageWithForm MyController.save
In read you read the data and render your page with the form. In save you save the data and redirect to read via read();
Hope this answers your question.