Submit form with a link and include a name value - html

I want to replace the form button
<input type="submit" name="submitForm" value="Send" />
with a link.
What I have at the moment is:
Send message
But I need include the name="submitForm" somehow.
Thanks for your help.

You can create a hidden input in your form:
<input type="hidden" name="submitForm" value="submitForm" />

What you can do is to use data-attribute ...
Send message
Then you can retrieve the name by ...
$(this).attr('data-name');

Related

Href link on input button submit

How can i bind this link
<a href="edit?id=<c:out value='${person.id}' />">
to input button "submit" ?
try something like that. Hope this will fix your problem
href="\edit?id={{person.id}}"
Typically if you are using a submit button, then you will be inside a form. An example of this would be:
<form action="edit?id=<c:out value='${person.id}' />" method="post">
<!-- form fields here -->
<input type="submit" value="Submit" />
</form>
In this case, the submit button is "tied" to the form, and will post the form data to the link in the action value.
I found solution :
<input type="hidden" name="from" value="${param.from}">
Servlet.class
response.sendRedirect(request.getParameter("from"));

How can I make an html button that passes a parameter?

I want a html button with parameter functionality.
new/?sorting=desc is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.
<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>
I want buttons that behave like these links:
Äldst först
Nyast först
If you want something to act as a link, then you should use a link.
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
You need to store the data in hidden inputs.
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
If you are using jQuery, you can use the code below.
This will fill a hidden input with the correct value when you click on one of the submit buttons.
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?

How to build a custom URL from a HTML form?

I have a HTML form like:
<form name="input" action="" method="post">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
I need to build a URL when the submit link is clicked and send the user to it, using the username from the form in the correct position in the URL.
URL:
http://example.com/htmlchat/init.html?init_room=1&init_user=USERNAME_FROM_FORM_HERE
Can someone help (an example would be great)?
Don't use POST when you want the data to appear in the URL
Do put all the data you want in your URL in the form
Get the names of your fields right
Put the base URI in the action
such:
<form action="init.html">
<input type="hidden" name="init_room" value="1">
<label>
Username:
<input name="init_user">
</label>
<input type="submit" value="Submit">
</form>
This is possible with either Javascript or a server side language such as PHP. With Javascript you want to update the action attribute.
You could use jQuery to do this.

HTML Form POST re-writing action attribute

I have an HTML form that I'm trying to get to post with part of a query string already inplace, but it keeps re-writing the URL.
<form id="mls_form" action="/index.php?option=com_mls&view=mls" method="get">
<label>MLS#:</label>
<input type="text" name="mlsnum" />
<input type="submit" value="Go" />
</form>
Output is:
http://www.mysite.com/index.php?mlsnum=value
It seems really simple, but I don't know why it's re-writing the action attribute.
Use the POST method rather than the GET method. The URL parameters will be sent as specified in the action attribute, and the form inputs will be sent in the post data. Your server script can then read them each using whatever API is appropriate (in PHP, $_GET versus $_POST, or find them all in $_REQUEST).
If you must use GET you can give the additional parameters as hidden input fields.
<form id="mls_form" action="/index.php" method="GET">
<input type="hidden" name="option" value="com_mls" />
<input type="hidden" name="view" value="mls" />
<label>MLS#:</label>
<input type="text" name="mlsnum" />
<input type="submit" value="Go" />
</form>

Simple Javascript error - Form submit doesn't append querystring

I want to submit a form to a URL appending few values as the querystring.
I am using this to call;
<form id="form1" method="GET" action="http://abc.appspot.com/_ah/xmpp/message/chat/">
<input type="text" id="data" />
<input type="submit" value="Submit" />
</form>
However, when I click on submit button, the URL that is fired is "http://abc.appspot.com/_ah/xmpp/message/chat/?"
The value of the "data" is not appended. Am I doing something silly here?
Thanks
Only fields which have name attribute are submited. This makes sense because how would you access those values without some key in POST of GET. So change your code to
<input type="text" name="data" id="data" />
Add name to input text and check
<input type="text" id="data" name="data" />
Give any form elements that are to be submitted a name attribute or they'll be ignored. So:
<input type="text" id="data" name="data" />
(You don't need the id attribute unless you reference it from somewhere else, but it won't hurt.)
Also it probably makes more sense to have method="POST" on your form.