How to set button's label without changing value in post - html

I've got this code in html:
<form action="/login/" method="post">
<input type="text" name="login">
<input type="text" name="pass">
<input type="submit" value="login" name="type" >
<input type="submit" value="register" name="type" >
</form>
When I submit this form it sends a get request with the value of the field of the button clicked. However I want to change the label of the button without changing the value sent in get. Is it possible or not?

Use a button element:
<button type="submit" name="type" value="register">Sign up for an account</button>
Note that old IE has problems with this.

Related

How can I hide the value from a input, so that the value is still accesable but won't be displayed?

I have a simple input form from the type submit and it contains the value $username:
<form action="index.php" method="POST">
<input class="submit" type="submit" name="submitbtn" value="'.$username.'">
</form>
How can I hide the value, so that it will not be displayed on index.php, but I still can access this value?
To hide fields in form from displaying change their type to hidden. Keep in mind that hidden field is just not displayed but anyone can read it/change it with browser devtools.
<form action="index.php" method="POST">
<input type="hidden" name="user_name" value="'.$username.'">
<input class="submit" type="submit" name="submitbtn" value="Submit">
</form>

How do I add a query to a get request with HTML?

I have made this:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit"><br>
Show: <input type="submit">
</form>
Is there any way I can pass a parameter when I press a different button? When I click now it sends me to links.php?link= which is good, but I want to do so that if I click one of the buttons, it sends me to links.php?link=&up=no.
I think I found a solution but it uses javascript, I want to do it with HTML only.
If you're looking to add a parameter based on what submit button was pressed, you can add a name to each of them:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit" name="direct"><br>
Show: <input type="submit" name="show">
</form>
Pressing the direct submit button will give:
?link=&direct=...
Pressing the show button will give:
?link=&show=...
edit
In the event that you want to pass a specific value for each button (which isn't tied to it's text like a submit input is), use the button tag instead of the input tag and pass it explicitly:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <button name="direct" value="foo">Submit</button><br>
Show: <button name="name" value="bar">Submit</button>
</form>
which would result in: ?link=&direct=foo and ?link=&show=bar

form action parameter not working

Test
<br><br>
<form action="index.php?page=test">
<input type="text" placeholder="enter text"> </input>
<button type="submit">Send</button>
</form>
Why is the link working correctly while the form gets me the url http://example.com/index.php? in the adress bar of the browser?
Every parameter i define in the action attribute is getting cut off
you have to use this code.
Test
<br><br>
<form action="index.php" method="get">
<input type="text" placeholder="enter text"> </input>
<input type="hidden" name="page" value="test">
<button type="submit">Send</button>
</form>
You are submitting a GET form. The data in the form will be expressed as a query string and replace the one in the URL in the action.
Move the data from the query string into hidden inputs inside the form.

html submit button stays on the same page

I am writing a mobile app in html5/css/js.
On the first page index.html I made a form with a submit button that point to result.html (with formaction="result.html").
But when I open index.html in Chrome just to debug the app, the submit button doesn't bring the user to result.html, but stays on index.html.
What's wrong?
Thanks
<form name="userdata" method="get">
<input type="number" step="any" class="hiddenbutton" name="userVolume" value="" >
<button type="submit" id="submitbutton" name="issubmitted" value="no" class="submitbutton" formmethod="get" formaction="result.html">Submit</button>
</form>
It doesn't work neither with:
<form name="userdata" method="get" action="result.html">
<input type="number" step="any" class="hiddenbutton" name="userVolume" value="" >
<button type="submit" id="submitbutton" name="issubmitted" value="no" class="submitbutton">Submit</button>
</form>
EDIT: I just discovered that there is no problem when I use firefox instead of Chromium (Ubuntu). Any hint on what's happening?
I think you need to explicitly state that as an attribute, i.e. an 'action' attribute in 'form'.
<form name="userdata" method="get" action="result.html">
<input type="number" step="any" class="hiddenbutton" name="userVolume" value="" >
<button type="submit" id="submitbutton" name="issubmitted" value="no" class="submitbutton" formmethod="get" formaction="result.html">Submit</button>
</form>
I removed all the action and formaction attributes to the form and submit button, and I decided to code my page as an SPA (single page app) so I move to next page using jquery:
$.mobile.changePage($('#result-page'));

Two submit buttons

I have two forms on a same page and I have two submit buttons...so how do I check if the user filled out the first form before clicking the submit button on second form? The first form posts the data to php page which presents on a same page as the html and the second form sends the data to another PHP page with thank you message....I mean how do force the user to finish the first form before clicking the submit button on the second form? if the user hits the submit button on the second form, the form directs to thank you page with out checking if the user finished the first form..how do I stop that?
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" />
<label for="file">Choose Photo:</label>
<input type="file" name="file" onchange="file_selected = true;" required>
<input type="submit" value="Submit" name="submit">
</form>
<form action="Send.php" method="post">
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit">
</form>
You can change the name field and then access the value on the server side.
For example:
<input type="submit" value="Submit" name="submitOne" />
If you're using php you could use something like this:
if(isset($_POST['submitOne'])){ /* first one pressed */ }
There are also some other options like using jQuery or javascript to validate first.
Try: http://bassistance.de/jquery-plugins/jquery-plugin-validation/