Assuming i have resource with 2 methods :show and :index. I need :index contain simple form with text field and submit button, when user insert data into text field, this data must be inserted into url as :id of resource for :show method.
for example page url looks like /s and when user type 123 into field in the form and press submit he must be redirected to /s/123. Can it be done with rails or html forms ?
Do you mid having s?id=123 I can't comment that is why I am posting if so then use this code
<form method="get">
<input type="text" name="id">
<input type="submit">
</form>
Remember always the name of the textbox will appear in the textbox now it is id so it should be s?id=value and when the name is changed for example to usd then the url will be s?usd=value.
Remember to perform a function with these urls use the below code.
if($_GET['textbox_name'] == true){//things to do}
Related
I've coded a simple form using HTML5 and CSS3 with a submit button.
My questions are:
Where is sent the form-data when the form is submitted by a client?
What data gets sent to the server?
And finally, do I need the <form> action attribute in the HTML5 markup?
1.
<form> has attribute action and here you can describe where your data will be send for example:
<form action="/something_action_on_your_server">
2.
Data which will be send is located in name attriubte of <input>, for example:
<form action="/something_action_on_your_server">
<input name="first_name" >
</form>
and if you submit your form, something action get data like: {name: 'something value from input'}
3.GET is HTTP method, which is used to visit page or send something public information, if you want send something private information you have to use POST method instead GET
for example:
<form action="/something_action_on_your_server" method='get' >
4. You don't have to set action attribute, but if you will not do it, your form will be send to your current page :)
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" ...>
I have a form like:
<form method="post" action="http://www.2-myWebSiteUri.com/file1.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
I would like to perform custom "action=" in FORM using POST (method) however I am not getting how to perform it. Form action should be like, for example:
<form action="http://www.2-myWebSiteUri.com/TEXTBOX1/file1.php" method="post" id="login">
BUT form should collect the text value (TEXTBOX1) from the TEXTBOX1 which user will enter and same should be used as a input value in action URL as given above in the place of TEXTBOX1. Suppose in TEXTBOX1, I have written input value as "pasta" & submitted via button, then action url should be like:
<form action="http://www.2-myWebSiteUri.com/pasta/file1.php" method="post" id="login">
or if input value is noodles then action url should be like
<form action="http://www.2-myWebSiteUri.com/noodles/file1.php" method="post" id="login">
upon submission.
I've small authentication based scripts in different directories of domain
www.2-myWebSiteUri.com and I am trying to create a single form so that all can be logged in using a single form. User will just enter directory name "such as pasta and noodles as given in above example". This form will be hosted on another domain www.1-myWebSiteUri.com and when user wants to make login any of the scripts then he will open:
www.1-myWebSiteUri.com/login.php and this is the same login form for which I want to have custom actions.
Actually, I am trying to use directories as a category of games which host few online games. Categories will not be fixed and it will be added randomly, so i want to keep TEXTBOX instead of a Drop Down. We may halt few features in the game for different users. You can take this as a different directories with different games which can be accessed only via authentication. I just want to post all the credentials using a single form instead of 100 forms for each game and it will be very tough to share all these login links with users.
I have tested couple of codes including javascripts however none of them are working. I will be more then happy if any of you assist me in this regard.
No, that will not work.
You need a middle-ware script. Your description is lacking detail but this may help.
Change action destination to middle.php
<form method="post" action="http://www.2-myWebSiteUri.com/middle.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
middle.php
Value of TEXTBOX1 is inserted into url as $txt1.
<?php
$txt1 = trim($_POST['TEXTBOX1']);
$txt2 = trim($_POST['TEXTBOX2']);
include("http://www.2-myWebSiteUri.com/$txt1/file1.php");
?>
Depending on values of TEXTBOX1 you may need to add urlencode:
$txt1 = urlencode(trim($_POST['TEXTBOX1']));
I was always confused about what the 'name' attribute did in html forms. From the textbook I read (html and css, design and build webpages by John Duckett), this is what it said about the 'name' attribute.
When users enter information
into a form, the server needs to
know which form control each
piece of data was entered into.
(For example, in a login form, the
server needs to know what has
been entered as the username
and what has been given as the
password.) Therefore, each form
control requires a name attribute.
The value of this attribute
identifies the form control and is
sent along with the information
they enter to the server.
From reading this, I always thought that, say in the database there is a field called "theUsersPasswordField" and a field called "theUsersUsernameField". I thought that, suppose there is a registration form, then the form would be like:
<form action="aURL" method="post">
<p>Please enter what you want your Username to be:</p>
<input type="submit" name="theUsersUsernameField" />
<p>Please enter what you want your Password to be:</p>
<input type="password" name="theUsersPasswordField" />
</form>
and then this way, when the information is sent to the database, it will know which information to put in the 'theUsersPasswordField" and which information to put in the "theUsersUesrnameField". Am I wrong?
What does name="next" mean? I see it often when I look at html forms, for example, here in this Django tutorial I am doing:
<form method="post" action=".">
<p><label for="id_username">Username:</label></p>
<p><label for="id_password">Password:</label></p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
In the tutorial I am doing, it says that
The html form contains a submit button and a hidden
field called next. This hidden variable contains a URL that tells the view where to
redirect the user after they have successfully logged in
now, how is 'next' a url? When I run the code, the form does in fact successfully redirect to the main page, but how does it know to redirect to the main page? Why does name='next'?
And how does the server know which information to treat as the username and which information to treat as the password? I though that that is what the 'name' attribute is used for?
The name attribute in a control element like input assigns a name to the control. It has two basic effects: 1) a control needs a name in order to be “successful”, which means that a name=value pair from it will be included into the form data when the form is submitted; and 2) the attribute specifies what will be included as the first part of the name=value pair.
It is entirely up to the server-side form handler what (if anything) it will do with the name=value pairs in the form data. They might have a simple correspondence in some database, but that’s just one possibility. And form handling need not be database-based at all.
The name attribute values have no predefined meaning in HTML. They are just strings selected for use in this context, and they may be descriptive or mnemonic, or they may not.
However, the choice of name attribute values may have side effects. Browsers may give the user a menu of previously entered data so that if you fill e.g. several forms (possibly in different sites) that have a control named email, you might be able to enter your email address just once and then accept whatever the browser suggests as input. This may be seen as a convenience or as a threat to data security. There is proposed set of “standard” names for many purposes in HTML5 CR.
For completeness, it needs to be added that in browser practice and according to HTML5 CR description of name, two names have a special meaning: _charset_ and isindex.
The name next is in no way special, but in this context, it appears to specify the next page to move to. It is defined for a hidden field, so it takes effect independently of user input.
and then this way, when the information is sent to the database, it will know which information to put in the 'theUsersPasswordField" and which information to put in the "theUsersUesrnameField". Am I wrong?
You have to write a script (for example in php) that will put the right values from your form (they are in the $_POST array) into the databse.
in your example $_POST['theUsersUsernameField'] will hold the username
<form method="post" action=".">
<p><label for="id_username">Username:</label></p>
<p><label for="id_password">Password:</label></p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
how is 'next' a url?
next is not the url.
the action="." is the url to wich the form redirects.
/ is the value that the script will evaluate to see what it has to do. (Normally you will have to change this into something else like 'check password')
In the $_POST[] array there will be a key $_POST['next'] and the value will be /
I am not familiar with Django but I hope this helps
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