bookthief
bookthief

Reputation: 2451

POST contents of a form to rest api

I have made a html user login form:

<html >
<head>

<title>User Login</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/signin.css">
</head>

<body>
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<input class="form-control" type="text" autofocus="" required="" placeholder="Email address">
<input class="form-control" type="password" required="" placeholder="Password">
<label class="checkbox">

</label>
<a href= "" <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button></a>
</form>
</div>
</body>
</html>

I now need to send the contents of the form, ie the username and password, to a rest api for authentication using the http POST command. I have no idea where to start with this and am having trouble finding a tutorial which assumes absolutely no knowledge of rest APIs and http commands. I'm extremely new to web development, can anyone point me in the direction of a good tutorial, or show me an example of what the javascript (I presume) might look like?

Upvotes: 21

Views: 60085

Answers (1)

carter
carter

Reputation: 5432

First fix your HTML. Then with the following no javascript is necessary:

<form class="form-signin" method="POST" action="URL_OF_REST">
  <h2 class="form-signin-heading">Please sign in</h2>
  <input class="form-control" type="text" required name="email" placeholder="Email address">
  <input class="form-control" type="password" required name="password" placeholder="Password">
  <label class="checkbox"></label>
  <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>

Upvotes: 22

Related Questions