I am making a program that would post on a webpage, to submit the form it has to "click" on a button:
<button class="form" type="submit">Send</button>
From what I know (not much) to submit a POST request when it's INPUT you must do name=value, but I don't know how I could do that with a submit button.
Basically I want to know what I must POST to the website so that it submits the form :p
Here's basic syntax for a form:
<form>
<input name="name" type="text"/>
<button type="submit"> Send </button>
</form>
Whatever backend you are using should be able to read POST request parameter "name" to read what that form contains.
If you're trying to make a form with just that one button, you can do that by just skipping that input element. Of course, there will be no data in that post request, but you can add the action attribute to the containing form and set it equal to a URL where you would like to redirect the user on button click.
Related
Basic question. If I have a form in my HTML (where in my case someone inputs a date), how can I have my users cause a GET request with the contents of that form instead of a POST.
e.g. form entry (e.g date)... so 20190312
what I am trying to achieve is such that AFTER the user submits the form.. the user is the lead to page that has
GET domain.tld/scriptname.php?variable=20190312
and then the system then processes the GET request accordingly.
thank you
Maybe i'm missunderstanding what you are asking.
This can easly be achived using builtin GET method in FORM tag
<body>
<form id="form" method="GET" action="scriptname.php">
<input id="date-txt" type="text" name="date">
<input id="search-btn" type="submit" value="Submit">
</form>
</body>
While filling up above field ad clicking "Submit" form will be submitted and you can see in your url path/or/page/scriptname.php?date=INPUT_FIELD_VAL
for every input in #form with a name, if GET method is used, you'll see a ?name=value in the url
What you describe is the default behaviour of a form. If you don't want a POST request, then don't use a method attribute to set the request type to POST.
<form action="//domain.tld/scriptname.php">
<input name="variable" value="20190312">
<button>Submit</button>
</form>
I have the form below ..
<form name="myForm" novalidate>
<label for="test_element">Test</label>
<input required id="test_element" type="text" ng-model="ctrl.test">
<button ng-click="ctrl.save(myForm.$valid)">
Submit
</button>
</form>
I'm using the Dynamic Assessment Plugin from here:
https://chrome.google.com/webstore/detail/dynamic-assessment-plugin/aahpafpbmmgednbflpalchnlbicaeppi
The tool doesn't give a great example of how to fix the error:
Submit buttons and image buttons allow users to explicitly request submission of the form and to control the change of context. Forms that are submitted by other mechanisms might change the user's context before they are ready, causing frustration or confusion.
What would be the best way?
I dont want to change <button> -> <input type="submit"> since there's angularjs code behind the scenes handling the submit
I have read a little bit about ng-submit, here's the link.
I think for that we can make it something like this:
<form ng-submit="ctrl.save()">
<input type="text" ng-model="ctrl.test">
<input type="submit" value="Submit">
</form>
I hope that documentation can help you :D
There's no obligation of having one submit button inside a form.
You can view an example in the documentation stating:
Finally, to make the form submittable we use the button element
with no input[type=submit] button.
You can also perfectly have no button at all, for instance a form consisting only in checkboxes.
<button type="submit" ng-click="ctrl.save(myForm.$valid)">
Submit
</button>
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
I have a button that is this <button id="btnSubmit">Submit</button> the problem is, I want the form tags to use this id so that is designed the way I want. And also this code, I have a few questions.
<form action="demo_form.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
what is the action="demo_form.php",input type="submit" do? And does the input type has any other "What do you call this stuff" besides submit?
The action="demo_form.php" sets the action, in this case, "navigate to file demo_form.php and send it the data".
<input type="submit" (...) > creates and element which submits the form e.g. executes the "action".
The method sets the way the data is submitted to the target of the action ("form_demo.php"), in this case get, which allows you to refer to the submitted data as $GET["name"] in PHP.
Possible input types are listed here.
You either give your <input type="submit" (...) > the id="btnSubmit" property or use javascript to submit the form after an event has been triggered.
MOr info on that is available here (i short: document.<get_the_form_element>.submit();).
I suggest you to take a look at this link. It describes all the basic concepts about how using forms. And you can also find a lot of information by Googling it.
The action attribute
The action attribute defines the action to be performed when the form is submitted.
The common way to submit a form to a server, is by using a submit button.
The input attribute
<input type="submit"> defines a button for submitting a form to a form-handler.
The form-handler is typically a server page with a script for processing input data.
If i understand your question correctly, these are my answers.
action
The action attribute describes the page to which the contents of the form are sent to. So if you have a sign up form with an input for an email, the text that is typed will be sent to the action path. It will be sent using the method described in the method attribute. So you can find your values in either the $_POST variable, or the $_GET variable, get is easy for being able to share the url and post is great for private information.
input
The input element is the actual way to input information (who guessed it). You've got an input of the type text for just text input, you've got checkbox for a true or false input and way way more see: w3schools
why don't you use
<input type="submit" value="Submit" id="btnSubmit">
Or if you want to use a button
<button id="btnSubmit">Submit</button>
Then from jquery or js you can submit the form.
And for this question,
what is the action="demo_form.php",input type="submit" do?
You should probably google it out. This is so basic.
Anyway, just a concise explanation:
action is the attribute where you will specify the code that will handle the form data submitted and input type="submit" will display a button in the page, clicking on it will submit the form.
There are a lot of types in input, the most common ones are
text
password
submit
What is the difference between HTML <input type='button' /> and <input type='submit' />?
<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.
<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.
The first submit button of the form is also the one being clicked for implicit submission, f.e. by pressing enter in a text input.
A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).
It should be also mentioned that a named input of type="submit" will be also submitted together with the other form's named fields while a named input type="button" won't.
With other words, in the example below, the named input name=button1 WON'T get submitted while the named input name=submit1 WILL get submitted.
Sample HTML form (index.html):
<form action="checkout.php" method="POST">
<!-- this won't get submitted despite being named -->
<input type="button" name="button1" value="a button">
<!-- this one does; so the input's TYPE is important! -->
<input type="submit" name="submit1" value="a submit button">
</form>
The PHP script (checkout.php) that process the above form's action:
<?php var_dump($_POST); ?>
Test the above on your local machine by creating the two files in a folder named /tmp/test/ then running the built-in PHP web server from shell:
php -S localhost:3000 -t /tmp/test/
Open your browser at http://localhost:3000 and see for yourself.
One would wonder why would we need to submit a named button? It depends on the back-end script. For instance the WooCommerce WordPress plugin won't process a Checkout page posted unless the Place Order named button is submitted too. If you alter its type from submit to button then this button won't get submitted and thus the Checkout form would never get processed.
This is probably a small detail but you know, the devil is in the details.
IE 8 actually uses the first button it encounters submit or button. Instead of easily indicating which is desired by making it a input type=submit the order on the page is actually significant.