i want to submit a form with <button>
instead of <input>
.
I know a <button>
cant handle the form like a submit <input>
and i have to use the onclick method.
I tried several things but it doesn't work
<button name="<?php echo $name; ?>" onclick="document.<?php echo $this->action; ?>.submit()"> ... ( Action URL of the form )
<button name="<?php echo $name; ?>" onclick="document.iso<?php echo rand(); ?>.submit()">... ( name of the form )
<button name="<?php echo $name; ?>" onclick="window.location.href='<?php echo $this->action; ?>'">... ( Action url of the form )
Does someone know an answer ?
The <input type="submit">, when inside a form element, will submit the form when clicked. Another useful 'special' button is the <input type="reset"> that will clear the form. The question is about <input> and <button> tags. You provided useful information about <input> in your answer, but it lacks the <button> side.
Definition and Usage The <input type="submit"> defines a submit button which submits all form values to a form-handler. The form-handler is typically a server page with a script for processing the input data. The form-handler is specified in the form's action attribute.
A click on a submit button sends the form's data to the web page defined by the action attribute of the element. A click on a reset button resets all the form widgets to their default value immediately. From a UX point of view, this is considered bad practice. A click on a button button does... nothing!
<button> is newer than <input type="submit">, is more semantic, easy to stylize and support HTML inside of it. While the other answers are great and answer the question there is one thing to consider when using input type="submit" and button. With an input type="submit" you cannot use a CSS pseudo element on the input but you can for a button!
You can use the type="submit"
like property of button
<button type="submit" name="<?php echo $name; ?>">Submit</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With