-2

i have a simple form and i wanna save inputs as a text file how i can do it ?

this is html code

  <div id="wrapper">
  <div class="main-content">
    <div class="header">

    </div>
    <div class="l-part">
      <input type="text" placeholder="Username" class="input-1" />
      <div class="overlap-text">
        <input type="password" placeholder="Password" class="input-2" />
        <a href="#">Forgot?</a>
      </div>
      <input type="button" value="Log in" class="btn" />
    </div>
  </div>
  <div class="sub-content">
    <div class="s-part">
      Don't have an account?<a href="#">Sign up</a>
        </div>
       </div>
        </div>

2 Answers2

0

With just html you can only display things on your site. To save things into say a database or in your case a text file, you have to use something like PHP or JavaScript. Also, the code you have right now doesn't contain any tag. You need this tag to tell the browser that this is a form and can be submitted to your website. Here is a simple example of a form that saves itself to a text file with PHP after submitting:

<?php

if ($_SERVER['REQUEST_METHOD'] === "POST") { // If someone is submitting a form
    $myfile = fopen("file.txt", "w") or die("Unable to open file!"); // Open/create the file to write in
    // Add parameters that are included in $_POST
    $txt = "First Name: " . $_POST["firstname"];
    $txt .= "\nLast Name: " . $_POST["lastname"];
    $txt .= "\nAge: " . $_POST["age"];
    fwrite($myfile, $txt); // Write $txt to file
    fclose($myfile); // Save the file
}

?>

<body>
<form method="post">
    <input type="text" name="firstname">
    <input type="text" name="lastname">
    <input type="text" name="age">
    <input type="submit">
</form>
</body>
J0R1AN
  • 583
  • 7
  • 10
0

You can´t do this with only HTML. Maybe this can help you: Is it possible to write data to file using only JavaScript?

You will need read the input data and save to a .txt file using javascript.

d3pod
  • 86
  • 10