Bootstrap. What's controlling where the form is sent? - html

I am using Bootstrap with forms. How the "method=" or "action="?
What is telling it what to do/where to go? Should there be a "method"?
What's controlling where the form is sent?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>my form</title>
<meta name="description" content="title page.">
<link href="twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<form class="well">
<label>test page</label>
<input type="text" class="span3" placeholder="Type something…">
<label class="checkbox">
input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Submit</button>
</form>
</body>
</html>

Your question has nothing to do with bootstrap. Those are form tag attributes.
Refer : Form_Tag
action Specifies where to send the form-data when a form is submitted
method Specifies the HTTP method to use when sending form-data. Default method is GET.
Example : <form action="next_page.html" method="get">
Notes on GET:
Appends form-data into the URL in name/value pairs
The length of a URL is limited (about 3000 characters)
Never use GET to send sensitive data! (will be visible in the URL)
Useful for form submissions where a user want to bookmark the result
GET is better for non-secure data, like query strings in Google
Notes on POST:
Appends form-data inside the body of the HTTP request (data is not shown is in URL)
Has no size limitations
Form submissions with POST cannot be bookmarked

Related

Regex in HTML Input pattern isn't working, but the expression is valid

I have a URL input field on a form, and this must accept only Youtube and Vimeo URLs. I got a regex like this:
(?:(?i)(?:https:|http:)?\/\/)?(?:(?i)(?:www\.youtube\.com\/(?:embed\/|watch\?v=)|youtu\.be\/|youtube\.googleapis\.com\/v\/)(?<YoutubeID>[a-z0-9-_]{11,12})|(?:vimeo\.com\/|player\.vimeo\.com\/video\/)(?<VimeoID>[0-9]+))
And it works. Tested here: https://regex101.com/r/PVdjg0/2
But when i have inserted this pattern on my field, it doesn't work. My field are aceppting any URL.
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<input type='url' required pattern='(?:(?i)(?:https:|http:)?\/\/)?(?:(?i)(?:www\.youtube\.com\/(?:embed\/|watch\?v=)|youtu\.be\/|youtube\.googleapis\.com\/v\/)(?<YoutubeID>[a-z0-9-_]{11,12})|(?:vimeo\.com\/|player\.vimeo\.com\/video\/)(?<VimeoID>[0-9]+))' title='URL Vimeo/Youtube.' name='video' placeholder='Video URL' />
<input type='submit'>
</form>
</body>
</html>
And i don't know why! I miss something? Somebody can help me?

How to create html form that directly goes to specific search on a website?

I know that the code below will go to the result page of google when the user types some texts and the submit button is clicked.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Hello!
</title>
</head>
<body>
<form action="https://www.google.com/search" method="get">
<input name="q" type="text">
<input type="submit" value="Submit Form">
</form>
</body>
</html>
But I try this with https://www.jitta.com/. It does not seem to have the same structure as google.
When searching on this website the url will be https://www.jitta.com/stock/bkk:ptt where "ptt" is the word that I want to search. Unlike google, if I want to search "ptt" the url will be https://www.google.com/search?q=ptt.
Can it be only HTML code? no other parts involved (like Javascript,...)
Appreciate anyone who answers this.

HTML Pattern Input to Allow Only Specific Numbers

I want the zip code part of my form, so only 5 numbers allowed, to reject anything that doesn't start with 46,52,53,54,60,61,62 using an html pattern
Try the below pattern (starts with one of the specified numbers and then allow 3 digits):
^(46|52|53|54|60|61|62)([0-9]{3})$
Here is the running HTML sample. You may use this pattern in Javascript as well if you want to perform the validation yourself:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Prescriptions</title>
</head>
<body>
<form action="#">
Country code: <input type="text" name="country_code" pattern="^(46|52|53|54|60|61|62)([0-9]{3})$"
title="Enter five digit number starting with specific numbers">
<input type="submit">
</form>
</body>

404 not found on method POST on form

I got this simple form on a page. I run this on localhost but when I run the form it shall redirect to http://localhost:63342/welcome.html
but instead I get the 404 not found message.
When I mark the url in the browser and hit return the correct page shows. But the redirect doesnt work when using method="POST" to localhost
Any idea how to solve this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST" action="welcome.html">
<input type="text" id="test" name="test"/>
<input type="submit" value="test"/>
</form>
</body>
</html>
I think you want to use the GET method instead of the POST method.
Have a look here for more information: http://www.w3schools.com/TAGS/ref_httpmethods.asp

Is it bad to wrap entire html document in <form>?

I have a database front-end that has several text fields for input on top of the page using post, and a pagination bar at the bottom of the page that uses the post method as well.
I've encapsulated the top inputs in
<form method = 'post'>
<Body>
//Inputs
//Table contents
//Pagination bar buttons
</Body>
</Form>
, but I've also extended the form so the form extends to the bottom of the document. (Database table is returned in middle of document) If I start a new form tag, the request will not include the previously entered text fields on the top, only the input inside the bottom form, so I can't use two forms.
<Html>
<Form method ='post'>
//Inputs
</Form>
//Table results
<Form method = 'post'>
//Pagination bar buttons
</Form>
</Html>
This will not work.
I want to ask, is it ok to encapsulate entire html doc in form tag? I don't want the client to send the entire doc in post or something.
If you mean this, that's fine:
<!DOCTYPE html>
<html>
<head>
<title>This is OK</title>
</head>
<body>
<form>
Everything
</form>
</body>
</html>
But
<form>
<!DOCTYPE html>
<html>
<head>
<title>Yes this is bad</title>
</head>
<body>
Something
</body>
</html>
</form>
or
<!DOCTYPE html>
<form>
<html>
<head>
<title>Yes this is bad</title>
</head>
<body>
Something
</body>
</html>
</form>
Is just invalid.
The only thing(s) that will be submitted in a form are values associated with input tags. So the entire document won't be submitted in the form. Only values associated with inputs.
Whether or not your design is "a bad idea" is hard to tell with the information given. I am unable to tell why exactly your pagination bar needs to be a form at all (rather than a link) but again, if you're worried about the entire document submitting in the form, that won't happen.