i assume this is a noob question, so sorry.
I'm trying to write this HTML-Page with a "form" that will work like a link on my raspberry pi.
So I used this code:
<form action="http://192.168.178.62/graph.pl?type=week">
<input type="submit" value="Blah" />
</form>
But instead of ending up at the adress I wrote in the code, I end up here: http://192.168.178.62/graph.pl? ("type=week" is missing, its just cut off)
Why is that, and how can I fix it?
thanks a lot!
When you submit a form with method="GET" (which is the default) then a new query string will be generated from the names and values of the successful form controls (since you don't have any, it will be empty). The new (empty) query string will replace the one in the action.
Options:
Use a link. (This is the best option. You aren't collecting any data from the user. You aren't making a POST request).
Move the data from the action to <input type="hidden" ...> elements.
Related
How can I prevent the URL I put in my forms and inputs from being encoded?
Code (JADE):
form(method="get" action="http://whateverdomain.com/blabla?")
input(type="text" name="action=basic&searchstr" size="31" value)
^That spits out this:
"http://whateverdomain.com/blabla?action%3Dbasic%26searchstr=mySearchQuery"
And that doesn't work — Which is why I'm asking for help here.
Context:
I'm trying to make myself a custom 'New Tab' page with search boxes connected to the sites (forums, etc) I often use.
Thanks in advance!
When using a form with methot="get", all your form elements' names and values will be appended to the query string of the action URI for the request that is issued when you submit the form.
When building the query string, the browser will percent-encode the names of the form fields.
If you have any query string parameters that you want to hardcode in the request URI, either add them as hidden form fields:
<form action="blabla">
<input type="hidden" name="action" value="basic" />
...
Or add them to the query string of the action URI:
<form action="blabla?action=basic" ...>
This is my webpage
www.domain.com/product/1
To update the product, I should submit to this URL
www.domain.com/product/1/update
In the product page, I have these forms to submit data
<form method="post" action="update">
<input type="submit" />
</form>
<form method="post" action="./update">
<input type="submit" />
</form>
Both forms do not work, because it will submit to
www.domain.com/product/update
They only work if URL is
www.domain.com/product/1/
If I hard code the product id in action
<form method="post" action="1/update">
<input type="submit" />
</form>
Then www.domain.com/product/1/ will not work, because it will submit to www.domain.com/product/1/1/update
What value should the action be to make sure the form can submit to correct URL?
If it is possible, I don't want to render absolute path or product id in form action.
As it stands to ensure this works in all situations you will need to use the product ID, like so: /product/1/update.
Another option, though, would be to make a couple of tweaks server side to make sure directory URLs always have a trailing slash.
You cannot achieve what you are asking for.
You have to specify either an absolute path or the product id.
You could generate the the product id programatically though.
You're having trouble because the action path product/1 is treated like a file not a directory, if the 1 had a slash after domain.com/product/1/ then you wouldn't have any problems. Like #sumitb.mdi suggested a base meta tag will work.
You're possibly using a framework, you might be able to utilise a URL builder function for 'named routes' or something.
I have a form:
<form method="GET">
<input type="text" value="hello" name="myname" />
</form>
If this form is submitted, I will end up at:
example.com/?myname=hello
What I would prefer is that when this gets submitted, I end up at:
example.com/hello
Is this possible?
No, you cannot change the way form submission works in HTML. (Using JavaScript, you can do transactions in a different way, without using HTML form submission.) When using method="GET", the URL gets constructed in a specific way; when using method="POST", the URL does not contain submitted data at all (it is sent outside the URL).
There is a trick that changes form submission in one way, but not quite the way you want. If the name of a control is isindex, then the control name and the equals sign are omitted; but the question mark is still there. That is, <input type="text" value="hello" name="isindex" /> would result in http://www.example.com/?hello. And Chrome has broken this when they removed the remainders of support to the isindex element.
If, for some special reason, you really need to make a form create requests like http://example.com/hello, then the simplest way is to set up a very simple server-side script that accepts normal requests that result from HTML forms and just passes them forward after modifying the URL in a simple way.
I have found an entry in html file
'<form action="?" ... '
I do not understand what it does.
Search in Google returned no results. Actually it is a Django template file, but I didn't find anything in django template documentation.
It uses the current URL with an empty query string as the action of the form. An empty query string. Empty. Meaning no query string at all. The query string will be no more. It will not be used. It will be gone. There will be no more query string after submitting the form. The query string will have vanished. Disappeared. Gone away. Become no more.
The action= atrribute has only value. i.e URL.
In simple english once your form is processed and you hit a submit button or enter you will be redirected to the URL you give to the action attribute
Example:
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
In the case of you question, if the action is "?" then the returned hash-string will be current URL plus "/?" appended which will take you back to the same page you were on.
action="" will resolve to the page's address. action="?" will resolve to the page's address + ?, which will mean an empty fragment identifier.
Doing the latter might prevent a navigation (new load) to the same page and instead try to jump to the element with the id in the fragment identifier. But, since it's empty, it won't jump anywhere.
Usually, authors just put # in href-like attributes when they're not going to use the attribute where they're using scripting instead. In these cases, they could just use action="" (or omit it if validation allows).
'<form action="?" ... ' strips the query string off of the URL when submitting the form, and submits the form to the current document address (i.e. itself).
Here is what that means:
Let's use the following URL as example:
ExampleSite.com**?SearchTerm1=chocolate&SearchTerm2=cake**
This URL contains the query string
'?SearchTerm1=chocolate&SearchTerm2=cake'
and sends that query string to the web site server, attached to the URL.
Sometimes, you want to ensure that the URL being passed to the server is stripped of any query strings (i.e. the query is string is removed completely) and only the URL is passed.
Let's say you bookmarked the page, using the full URL and query string ExampleSite.com?SearchTerm1=chocolate&SearchTerm2=cake****
Now you get to that page, and there is a search form.
You decide to use the search form to search for something new...
'<form action="?" ... ', as used above, removes the query string from the URL when the form is submitted, and submits the form to the same page that it came from (usually a 'controller' (a page with programming that determines what to do with the information sent to it by the user) ).
<form name="test" action="process.php" method="get">
<input type="submit" value="Submit">
The action used here will take you to the process.php page after clicking the submit button.
In short the action= is used to go to the specified page(mentioned in the action=) after filling the form and submitting.
When we don't know the url to go by submit the form we can specify
like this, It will reload the same page by appending question mark(?)
to url.
I.e, Form is submitted for same page itself. It identifies
form is reloaded.
Note: We can leave action property blank, even though it will work!
action is an attribute used in forms to specify the URL of the file that will process the input control when form is submitted
I have a form to sign up to getting a rss feed through Feedburner.
this is the code -
<form action="http://feedburner.google.com/fb/a/mailverify" method="post">
<p><input name="email" type="text" /></p>
<input name="uri" type="hidden" value="dafyomi" /><input name="loc" type="hidden" value="en_US" /><input type="submit" value="click here to send" /></form>
<p> </p>
I want it to also sent the form data to a new window, and also change the window the user is on now - to a thank you page on the site.
Any ideas?
Thanks!
In clean HTML — impossible.
You can use JavaScript for this but it's ugly, breaks usability and probably most browsers will block it thinking you're trying to show an advertisement.
And as forcing opening a new window/tab/whatever is getting deprecated too, some browser may even ignore your ‘new window’ and try to open the thing in current tab. This would lead to undefined behavior of it trying to open two things in same window.
You may think about using one target page and <object/> or frames to display another if that's important. But that's not very usable too.
PS. And in all cases, the form can be submitted only to one of the pages. The second one will be plain GET.
I would like to suggest to use jQuery Ajax Form Plugins for this case. You can done two actions with one form submit by this way...
$('form').submit(function() {
$(this).ajaxSubmit({
url: myurl, //ajax request to myurl
success: function() {
return true; //submit form
}
});
return false;
});
I would add the "Thank you!"-phrase to the results page - after all, it can only be a line or two long, right?
If you feel that is not an option, you might want to do the something like this instead:
Form submits to server, and relevant data required to view the results page are saved in a Session
Redirect to Thank You-page, with a link to the results page.
Link triggers GET-request for the results page, and the results can be shown thanks to the Session variable.
If the page should only be available once, abandon the session.