Using form_for tag with get method
You can pass the raw HTML attributes using :html
if you need to. For Rails 3:
<%= form_for(@post_filter, :url=> filter_path, :html => { :method => 'GET' }) do |f| %>
Update and in Rails 4, per @andre.orvalho's suggestion below, the method
parameter can be supplied directly:
<%= form_for(@post_filter, url: filter_path, method: :get ) do |f| %>
Call GET method by not using the form html tag
There are several http verbs (GET, POST, PUT, DELETE, PATCH). But when you are talking about old-school web development, there are really only 2 (GET and POST). A form has the option to submit using GET or POST, but every time you type a URL into the address bar of your browser, you are actually making a GET request. That means that every time you click on a link you are making a GET request.
This is basically a long way of saying all you need to due is add:
<a href="http://example.com/path/to/whatever?q=ifyouneedtoaddquerystrings">Click On Me!!</a>
The kicker here is you can't add an data to the body of your request. But it doesn't seem like that is what you need.
How do I use get method to input values to form field with PHP
In your HTML, add the input field like this:
<input type="text" name="username" value="<?php echo htmlspecialchars($_GET['username']); ?>" />
Basically, the value attribute of the text field needs to be set to:
<?php echo $_GET['username']; ?>
The code right above this is how you would output a get variable in php whether you are putting it in a text field or not.
To access get variables, always use:
$_GET['variable_name'];
Then you can assign it to variables or pass it as a function parameter.
**However, I strongly do not recommend passing sensitive information like usernames and passwords through GET variables. **
First off, users could change the URL hence changing the variable. They could also accidentally share the URL with someone and that could give someone else access to their account. I would recommend that you create a cookie on their machine that is set to a random ID, and then in a MySQL database, associate that ID with a username so that you know the user can't accidentally share their account or change their username through the URL.
which form tags values of HTML can be passed in get method?
all tags can be sent in GET method on form submit except <optgroup><fieldset><label><div>
(mentioned in your question)
in url you will see them as key=value&key=value
pairs
for <option>
, its sent in the name of <select>
HTML form send data by GET instead POST
It should be a post (assuming that you forgot the closing tag only in your example). I added your code and put the closing tag in an html file and submitted in Chrome. This is what I see in the network trace:
Also look at this question in case you are doing the same.
Passing value from form tag to an action method not working
Drop the '/id'
from url, simplify it and use id attribute
in your text box and it will bind.
View
<form action="api/Values/Delete" method="post">
<fieldset>
<div style="text-align: center">
DELETE
<input type="number" id="id" value=""/>
<input type="submit" value="Submit"/>
</div>
</fieldset>
</form>
Controller
[HttpPost]
public IHttpActionResult Delete(int id)
{
var delete = Connection.dm.Student.FirstOrDefault(s => s.StudentID == id);
if (delete != null) {
Connection.dm.Student.Remove(delete);
Connection.dm.SaveChanges();
}
return Ok(Models.db.test);
}
rails 'form_tag' defaults to POST method but submits with GET method
You can directly use route and its http request, try this
<%= form_tag( '/orders/users/create_user', :method => :post ) do %>
Routes.rb
post "/orders/users/create_user" => "orders#create_user", :as => :create_user
or
match "/orders/users/create_user" => "orders#create_user", :via => :post, :as => :create_user
Related Topics
Cron Is Running in Home Directory Instead of File Directory
Validate That String Contains Only Allowed Characters in Ruby
Ruby Outputting to the Same Line as the Previous Output
How to Use Headless Chrome with Capybara and Selenium
How to Define a Method in Ruby Using Splat and an Optional Hash at the Same Time
Cucumber Step Definition for "Given That I'm Logged In"
Ruby/Rails - How to Validate Against Decimal Scale
Nesting Too Deep' Error While Retrieving JSON Using Httparty
How to Call a Method That Is a Hash Value
How to Click a Link in a Table Based on the Text in a Row
Monitor Ruby Processes with Monit
Yaml::Load Raises Undefined Class/Module Error
Ruby Equivalent of C#'s 'Yield' Keyword, Or, Creating Sequences Without Preallocating Memory
Ruby Defining Operator Procedure
Rvm Install Ruby-1.9.3-P286: Error Running 'Make -J 9' (Osx: Mountain Lion)