Steps for creating a login form that redirects to a website

Looking to improve the HTML code

(reviewing changes)

Still learning how to create a website, so there might be errors in the code. I'm using neocities.org as the platform. I tried customizing the HTML source but struggling with removing the white space around the boxes. Will work on fixing it later.

I'd like to learn how to create a form that redirects to a new page upon entering the correct answer.

Website URL:

UPDATES:

<!DOCTYPE html>

<html>

<head>


<style>
div {
    height: 200px;
    width: 400px;

    position: fixed;
    top: 50%;
    left: 55%;
    margin-top: -100px;
    margin-left: -200px;
}
body {
 background-image: url("https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fgetwallpapers.com%2Fwallpaper%2Ffull%2F4%2Fc%2Fc%2F36974.jpg&f=1&nofb=1");
 background-color: #cccccc;
}
function {
  color: red;
}

</style>

<body>


  <script>
    var incorrectCount = 0;
    var correctPassword = "randompassword"
    function checkPassword(){
        var enteredPassword  = document.getElementById("txtpassword").value;
        if(enteredPassword != correctPassword)
            incorrectCount++
        else{
            incorrectCount = 0
            document.getElementById("userMessage").innerHTML = "Correct Password !!"
            window.location.href = "http://www.w3schools.com";
        }

        if(incorrectCount == 3){
            document.getElementById("userMessage").innerHTML = "Incorrect password entered 3 or more times"
            document.getElementById("userMessage").style.visibility = "visible";
        }
    }
  </script>



  <div>
   <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <title>Login</title>




<form>
        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="text" id="randompassword" name="login" value="" placeholder="Username"></p>
        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="password" id="something" name="password" value="" placeholder="********"></p>
           <a class="submit"><input type="submit" id="loginbutton" onclick="checkPassword()" name="commit" value="Login"><br>
             <label id="userMessage" style="visibility:hidden;"></label>


</a>

  </form>

    </div>

</body>

</html>



Answer №1

When dealing with form data in html/css on the receiving page, there are specific methods to follow. If the method attribute is omitted, the default is method="get", which sends the form data in the url after the question mark (?). In such cases, Javascript can be used on the receiving page to handle the form data.

If the method attribute is set to "post", PHP can be used to process the form data. Below is an example of html code that sends input values to a process.php file:

<form method="post" action="process.php">
  <p><input type="text" name="username" value=""></p>
  <p><input type="password" name="passcode" value=""></p>
  <p class="submit"><input type="submit" name="submit" value="Submit"></p>
</form>

In the process.php file, the form data can be accessed and manipulated as needed:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $username = (!isset($_POST['username']))    ? "" : trim($_POST['username']);
  $password = (!isset($_POST['passcode'])) ? "" : trim($_POST['passcode']);
  // Perform actions with $username and $password here
}
?>

Answer №2

<form action="http://google.com">
        <p><input style="background-color:red;color:black" type="text" name="login" value="" placeholder="Username"></p>
        <p><input style="background-color:red;color:black" type="password" name="password" value="" placeholder="********"></p>
        <a class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
  1. If you wish to simply redirect to a publicly hosted site such as Google or Stack Overflow, omit the POST method as it indicates data is being sent to the site.
  2. Always use http:// or https:// - failing to do so will lead the code to search for the page/website in your HTML page directory.

EDIT - 2

<!DOCTYPE html>
<html>
<head>
<style>
div {
    height: 200px;
    width: 400px;

    position: fixed;
    top: 50%;
    left: 55%;
    margin-top: -100px;
    margin-left: -200px;
}
body {
 background-image: url("https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fgetwallpapers.com%2Fwallpaper%2Ffull%2F4%2Fc%2Fc%2F36974.jpg&f=1&nofb=1");
 background-color: #cccccc;
}
</style>

<body>

  <script>
    var incorrectCount = 0;
    var correctPassword = "randompassword"
    var correctLoginId  = "randomlogin"
    function checkPassword(){
        var enteredLogin  = document.getElementById("txtUserId").value;
        var enteredPassword  = document.getElementById("txtPassword").value;
        if(enteredPassword == correctPassword && enteredLogin == correctLoginId){
            incorrectCount = 0
            document.getElementById("userMessage").innerHTML = "Correct Password !!"
            window.location.href = "http://www.w3schools.com";
        }
        else{
            incorrectCount++
        }

        if(incorrectCount == 3){
            document.getElementById("userMessage").innerHTML = "Incorrect password entered 3 or more times"
            document.getElementById("userMessage").style.visibility = "visible";
        }
    }
  </script>



  <div>
   <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <title>Login</title>




        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="text" id="txtUserId" name="login" value="" placeholder="Username"></p>
        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="password" id="txtPassword" name="password" value="" placeholder="********"></p>
        <input type="submit" id="loginbutton" onclick="checkPassword()" name="commit" value="Login"><br>
        <label id="userMessage" style="visibility:hidden;color:red;"></label>
    </div>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing my table to not display?

I imported a CSV file with data on time, events, and location. The data was loaded into separate arrays for each column. I attempted to display the arrays as an HTML table using a for loop, but the table is not showing up. What could be causing this issue? ...

Does Google's caching process differ when using <span> tags instead of <h> tags for headings?

Does the choice between using <span class="heading"> and <h> tags impact search engine optimization for Google? As I'm constructing a website, I decided to style the headings and subheadings with <span>. However, I began to wonder i ...

Refresh the data in the DataTables table using a fragment

Currently, I am attempting to reload a fragment using ajax. However, after the reload, my event select and row count do not function properly. It seems that the default configuration is not behaving as expected: @PostMapping("/admin/add") ...

The peculiar characteristics of the dragLeave event in various web browsers

I observed a peculiar behavior while working with drag events in Internet Explorer 11. It seems that adding a 'width' property to the elements triggers the dragLeave event, whereas without it, the event does not fire. Can anyone shed light on why ...

Is it possible for images underneath to receive focus when hovering over them?

I'm struggling with a layout of thumbnails on my page. We'll refer to them as A, B, C, etc. They are currently displayed like this: A, B, C, D, E, F, G, H, I, J, K, L, M, N... and so on. When you hover over one thumbnail, it enlarges by 2.5 t ...

How can I set a default radio button selection when the page is loaded?

Input your radio button code below: <ion-radio ng-model="data.gender" ng-required="true" ng-value="'male'">Male</ion-radio> <ion-radio ng-model="data.gender" ng-required="true" ng-value="'female'">Female</ion-rad ...

Showcasing Portfolio Work in a User-Friendly Mobile Design

Currently revamping my portfolio website and looking for ways to optimize the display of my personal projects. I have a card-like interface in place that works well on desktop but only shows one project at a time on mobile devices. Seeking solutions to imp ...

Guide on loading a div with a flash object without showing it on the screen (element is loaded but remains hidden)

Is there a way to achieve an effect that is somewhere between using display: none and visibility: hidden? Specifically, I am trying to have a div element (containing flash content) loaded but not displayed on the page. Just for clarification: I have embed ...

Reformat an input number by substituting commas with periods

Here's the code I'm working with: <input type="number" tabindex="3" placeholder="Item Price" step="0.01" min="0.10" max="999.99"> An example value inside this input is 1,95. I need to replace the comma with a dot. Can this be done using ...

Learning to use Material-UI: Wrapping a list into columns

Currently, I am using Material-UI to display a list of checkboxes, similar to the example shown here. The problem arises when my list contains around 30 items and I am placing them inside a dialog box. I want the checkbox list items to stack vertically up ...

Ways to display an image within a div when hovering over a specific element?

I am working on recreating a specific effect found at in the section titled 'Capture and share anything quickly'. The effect involves displaying an image in the right block when hovering over the left text. I have successfully implemented this e ...

Displaying Text and Images on a Sliding Carousel with a Static Background Image

I am currently experimenting with the Materializecss Image Slider. My goal is to have a fixed full-screen background image while the texts and images slide over it. Initially, I tried setting the background-color of the slider class as transparent, but un ...

Is there a way for me to merge the specifications of two itemscopes in order to depict a

Adding microdata to a page can be challenging when the data for an item is spread across different parts of the page. If there are two span elements with an itemscope attribute, it would be beneficial if search engines could merge these two itemscopes into ...

What is the best way to anchor an image to the bottom right corner while also adjusting its position as

Hey there! I have a challenge where I want to anchor an image at the bottom right corner of a webpage. Initially, it works perfectly using this CSS: .logo img{ position: absolute; bottom: 0; right: 0; } However, when I resize the window, the ...

Position a div at the center of the page while aligning it inline with another div

Is there a way to center an element on the screen while having another element positioned to its left? I have tried using float left and adjusting the padding of the center element to match the width of the left element. However, this method may not work ...

The function TagBuilder.MergeAttributes is malfunctioning

My attempt at creating a custom helper in MVC is not working as expected. The custom attributes are not being added to the HTML: Custom Helper Function public static MvcHtmlString MenuItem(this HtmlHelper helper, string linkText, string actionName, strin ...

Utilizing keyboard shortcuts for webpage navigation (within a content script)

Just to clarify, I'm not looking for code assistance right now. I mostly need a starting point. My goal is to create a Chrome browser extension that enables me to use keyboard keys for navigation on a specific webpage. The page in question belongs t ...

Align the content of the list items to the center and position the list in the center of

I am struggling to get the List centered beneath "Contact Me" and the hr tag. Both of those elements are perfectly centered in the column, but the list and icons are aligned to the left. Ideally, I would like them to be in the center like everything else. ...

Adjust the standard size of the IMG tag using CSS

I have a simple image tag with an incorrect URL http://jsbin.com/monivava/1/edit <img src="http://placekitten!!!.com/g/200/200"> The issue is that the default size for this unsuccessful image is 18x20 (at least in Webkit), but I want it to be 0px ...

CSS animation is supported on most browsers with the exception of Safari

I'm facing an issue with my animation that works fine on all browsers except Safari. I've tried using the autoprefix extension in VSCode to automatically add CSS vendor prefixes, but the animation still isn't functioning correctly. Here&apo ...