Use Answers of HTML Form In Link to Submit - html

I was hoping someone could help me with submitting the answers to an HTML form as parameters of a link. So for example, lets say the form looked like this:
Name: _______
Question: ______
Then, when the user types their answers, and hits submit, I want the answers to be placed as parameters of the link so that if the user types:
Name: Joe Smith
Question: How do I win?
When the user then presses submit, a link that looks like the following would be submitted:
https://myurl.com/Submit.asp?Name=Joe%20Smith&Question=How%20do%20I%20win?

You need to use ,refer link
method="GET"
more genrilize,
<form action="url" method="GET">
<input type="text" name="Name" value="" />
<input type="text" name="Question" value="" />
<input type="submit" />
</form>
So when you submitthe form it will automatically build the querystring and append it to url.
go through submitting form here

Use Method type GET for your form

Related

How do I define what is sent in a post request (ASP.NET)

I have an html form that submits a post request.
<form asp-controller="Home" asp-action="Check" method="post">
<textarea id="uname" name="uname">myName</textarea>
<input type="submit" name="req" value="finish" />
<input type="submit" name="req" value="begin" />
</form>
When it submits a request using e.g. the word "myName" in the text box and the "finish" button it will send the following post request body:
uname=myName&req=finish
What I don't understand is how post requests are assembled when I push the button - how can I add more values to the request? are these all automatic? can I attach more attributes within button tags e.g. personalid="123" and send these in the request also? I'm aiming so that when I click the finish button I can send the req=finish as well as personalID=123 but I'm not sure if this is possible just by putting in more attributes.
If the personalID is meant to be constant you could put it in a hidden field:
<input type="hidden" name="personalID" value="123"/>
If users are meant to be able to edit the id you could use a textbox:
<input type="text" name="personalID" value="123"/>

Redirect to selected site with variable which i got

<form action="/subsite/" method="GET">
<input type="text" name="" placeholder="Your Nick">
<input class="button" type="submit" />
</form>
I want to redirect I mean it should looks like
www/subsite/text
What should I use ? POST ?
The method="get" means that the parameters (and values) will be sent in the query string (the stuff after the question mark in the URL). eg.
/subsite?input_field_name=input_field_value
In your case, the input field doesn't have a name, which will cause problems. You probably want something like this:
<input type="text" name="nickname" placeholder="Your Nick">
So if you submit this form:
<form action="/subsite" method="get">
<input type="text" name="nickname" placeholder="Your Nick">
</form>
Then after submitting, the browser will go to:
/subsite?nickname=value_of_nickname_variable
If you use a method="post", then the form data (variables) will be sent along in the request body, not the query string. There are other differences between get/post, but that's one of them :)
If you just want to do a simple redirect when clicking the button, you could use javascript instead, eg.: window.location.href='/my_url_path_here'

Input text to link with a form?

I've been working on having a form where a user can input a subreddits name in a input form and be taken to it, but not been working out well. I've tried using get and name="q" but it makes the address funky.
What I have so far:
<form method="post" action="http://www.reddit.com/r/" style="margin-left:5px;margin-right:5px;margin-bottom:0px;">
<input class="form-control" value="" placeholder="Subreddit Name">
</form>
If you're not getting what i'm trying to do: A user types text into an input, the text they typed would be sent to an address as reddit.com/r/(whatever the user typed)
Not knowing from your question whether or not you have access to server-side coding, and based on your answers in the comments, the following should work for you. Note that if a browser has JavaScript disabled, this will bring the user directly to http://www.redit.com/r/
If you have access to server-side scripting, you could add a catch on your server as well to avoid this.
<form method="post" onsubmit="document.location='http://www.reddit.com/r/'+document.getElementById('subredditname').value;return false;" action="http://www.reddit.com/r/" style="margin-left:5px;margin-right:5px;margin-bottom:0px;">
<input id="subredditname" class="form-control" value="" placeholder="Subreddit Name">
</form>
You can do this easily with PHP.
User types text into input field
<input type="text" name="user_text" />
After form submit, run PHP code
$page = $_POST['user_text'];
//send user to website
header('Location: http://reddit.com/r/' . $page);

How to forward data from one jsp A to jsp B and then all data to final servlet?

I have two JSP pages A and B and also a Servlet.
The flow is like this:
User fill in some information in page A
Then the user fill in some other information in page B
After the user finishes B, he/she will click a button and submit all data (from both A and B) to the Servlet.
How should I design this?
My plan is
In A's next button, it is actually a <a> tag with link to the href of B. All information from A should be passed to B via that link. I don't know how to do this step.
In B's finish button, it is a form input submit button. I don't know whether I can or how I add A's data into this form.
Anyone can help me out?
Thanks
In your A.jsp create a link, for e.g.: Go to B
Pass your parameters from URL.
In B.jsp use expression language to get parameters values:
<form action="FinalServlet" method="post">
<input type="text" name="p" value="your value"/>
<input type="hidden" name="p1" value="${param.param1}"/>
<input type="hidden" name="p2" value="${param.param2}"/>
.......
<input type="submit" value="Finish"/>
</form>
Hope this helps.
EDIT:
If you want to use a form with input fields in A.jsp:
<form action="B.jsp" method="post">
<input type="text" name="param1" value="value1"/>
<input type="text" name="param2" value="value2"/>
.......
<input type="submit" value="Finish"/>
</form>
You will receive parameters in B.jsp using the same EL.

How can I automatically submit the Facebook URL sharer form?

I am trying to figure out, how can I automatically submit a url at the following page
http://www.facebook.com/sharer.php
without actually clicking on the submit button.
Thanks.
You can find that from the page source. There is a form defined...
<form action="/sharer.php" method="get">
and the button is a submit button, which means that when you click the button, the form data is sent as a get request to http://www.facebook.com/sharer.php - in other words, it submits back to itself.
Update - asker wants to know how to submit the form without clicking on the link.
The form is:
<form action="/sharer.php" method="get">
<input type="text" class="inputtext DOMControl_placeholder" id="share_input" name="u" placeholder="http://" value="http://" title="http://" />
<input type="hidden" name="appid" value="2309869772" />
<label class="mrm uiButtonNoText uiButton uiButtonConfirm uiButtonMedium" id="share_submit">
<input value="Share" type="submit" />
</label>
</form>
So you need to GET a URL with form data something like the following
http://www.facebook.com/sharer.php?u=your_encoded_url&appid=yourappid