Posting HTML forms from other forms - html

For layout reasons, I have to separate the "submit button" of a form from it. So I made the form fields in form1 and the submit button in form2, How can I make the submit button of form2 post the data in form1?
the publish button is form2, how can I make it send the data of the form1 ( the fields under ) using only HTML.

Use the form attribute.
<input type="submit" form="id_of_the_form_it_should_submit">
(NB: Limited browser support)

You can use jquery, to submit it. submit()

Related

LastPass shows prompt to save password after clicking back

I have a single page React app with a simple login form with two buttons LOGIN and BACK. If I click BACK LastPass still offers to save the entered username/password, even though I didn't login.
Is there any way to tell LastPass that the back button is a cancel button for the login form and that it shouldn't try to save the username/password in that case?
HTML looks something like this:
<input name="username" type="text" />
<button type="submit">LOGIN</button>
<button>BACK</button>
You can use <input type="reset" /> or <button type="reset">.
As its name says, a reset button is ment to cancel a form. When it is activated, all user inputs are cancelled and the fields are reset back to their default values, i.e. the ones that were specified in the HTML code.
In JavaScript, You may intercept an activation of the reset button by using the reset event on the parent form, i.e. form.onreset=..., form.addEvementListener('reset', ...) or <form onreset="...">.
Note that, as for submit buttons, it's a bad practice to intercept the click event directly on the button by using onclick: although there is no universal standard way to cancel the form as there is with the enter key to submit it (escape key don't cancel the form by default), you can't be sure that there is no other way to cancel the form than click on the reset button.

HTML Form action goto page

For a Project, in which we are not yet allowed to use php, I want to create a login page. I just can't figure out how to make it so the cancel button and the submit button take me to predefined pages. I want to be able to input some dummy data into the username password fields and when I press submit be sent to the "logged in" part of my site.
<button type="submit" value="profil.html">Login</button>
I tried it like that but it doesn't work. I also tried that:
<form action="profil.html" method="get">
You can use little bit of js to achieve it cleanly.
<button value="Cancel" onclick="window.location.href='otherpage.html'"> Cancel</button>
Set the action in the form. Use a submit button to submit the data to that URL.
"Cancel" means "Give up on the form and go somewhere else". To go somewhere else: Use a link.
<button>Login</button>
Cancel

Alternative for nested forms

I need nested forms. I know that they are not allowed in HTML, so I decided to set several submit buttons for one opened form.
In my controller I need to check which of the submit buttons is pressed. How can I do that?
I'm trying to give buttons names like this:
<input class="btn btn-primary" name="editAction" type="submit" value="Save"></button>
Then in my controller I check them like this:
if ($this->input->post('editAction'))
But it doesn't work.
If you are bound to have several submit buttons in your form, then you can do 2 things :
1) Convert submit buttons into normal buttons and submit form using ajax. This will solve your problem.
2) Convert submit buttons into normal buttons and maintain a hidden field on your form and onClick event of all buttons, just put the id of the button in that hidden field as a value, and then using jQuery, submit your form and then in your controller, check your hidden field value and then process the form.
if ($this->input->post('hidden_field_name'))

HTML form - normal button prevents submitting the form on Enter

I have a form with some
<button>
elements and a normal
<input type="submit">
button to submit the form.
However, when I press Enter when I'm in a textfield, the form does not get submitted but much rather the first Element is "pressed".
How can I change this behavior?
I would recommend changing the <button> tag and turning it into an <input type="button" /> tag. This should force the form to submit the way you want.
You can use javascript to capture that the Enter key was pressed and submit the form.
See this example.
For a complete answer, could you please post your HTML?

If an HTML form has two <input type="submit"> buttons, how do I know which got clicked?

Suppose I have the following HTML form:
<form>
...
<input type="submit" name="queue" value="Queue item">
<input type="submit" name="submit" value="Submit item">
</form>
How do I know which button the user clicked (without using javascript)?
I looked at submitted data and it seems that when "Queue Item" is clicked then "queue" = "Queue Item" gets sent to the server. And when "Submit item" is clicked then "submit" = "Submit item" sets sent.
Can I rely on this behavior? Is it documented somewhere in the standard on HTML forms? How do you guys do it?
Yes, you can rely on this; it's fully documented here. The specific relevant lines say:
When a form is submitted for processing, some controls have their name paired with their current value and these pairs are submitted with the form. Those controls for which name/value pairs are submitted are called successful controls.
and
If a form contains more than one submit button, only the activated submit button is successful.
Yep you can rely on that behaviour.
When <input type="submit" name="queue" value="Queue item"> is clicked, the field "queue" will be set and "submit" will not be.
Whereas when the other gets clicked, the field "submit" will be set, and "queue" will not be.
If you're not assured by this, you can split them into 2 forms and work on it that way.
You can rely on this behavior. You get the value of the input. I would use javascript to toggle a hidden form value, but since you mentioned no javascript you do not have multiple choices.
It's a standard. Since it's an input tag, and has a value, that means you get the value submitted.
Split the form into two forms, replicating any other inputs needed by the other action. Or, if you really just need to know if the user wants to "queue vs. submit" the item, change both submit buttons to radio selections to toggle between the two options, and have a new, separate "submit the form" button.
In that situation if you want a one-click option, you could use Javascript to detect when one of the radio buttons is selected, and auto-submit the form instantly. (Using Javascript for user interface, rather than form handling)