如何从一个HTML表单中获取默认文本输入值到另一个HTML表单中

huangapple go评论64阅读模式
英文:

How to get default text input value from one HTML to other HTML form

问题

我正在进行基本的登录。在一个HTML文件中,我有用户输入电子邮件ID文本框,一旦点击发送OTP按钮,将重定向到下一个HTML页面,其中包含电子邮件和OTP字段。在电子邮件字段中,用户在第一个HTML页面中输入的内容应自动填入第二个HTML电子邮件输入字段文本框中。

以下是我的第一个HTML页面:

<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
   <head>
      <meta charset="utf-8">
      <title>Employee Login </title>
      <link rel="stylesheet" href="{% static 'style.css' %}">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
   </head>
   <body>
   <center>
      <h1> </h1>
      <h2> </h2>
      <h3> Employee Feedback Login</h3>
   </center>
      <div class="wrapper">
         <div class="title-text">
            <div class="title login">
               Login
            </div>

         </div>
         <div class="form-container">
            <div class="form-inner">
               <form action="" method="post" class="login">
                  {% csrf_token %}
                  <div class="field">
                     <input id="Employee_Mail" type="text" placeholder="Email Address" name="Employee_Mail" required>
                  </div>

                  <div class="field btn">
                     <div class="btn-layer"></div>
                     <input type="submit" value="Send OTP">
                  </div>
               </form>

            </div>
         </div>
      </div>
   </body>
</html>

和我的重定向(第二个HTML页面):

<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
   <head>
      <meta charset="utf-8">
      <title>Employee Login </title>
      <link rel="stylesheet" href="{% static 'style.css' %}">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
   </head>
   <body>
   <center>
      <h1></h1>
      <h2> </h2>
      <h3> Employee Feedback Login</h3>
   </center>
      <div class="wrapper">
         <div class="title-text">
            <div class="title login">
               Login
            </div>

         </div>
         <div class="form-container">
            <div class="form-inner">
               <form action="validate/" method="post" class="Validate OTP">
                  {% csrf_token %}
                  <div class="field">
                     <input type="text" id="mail" placeholder="Email Address" name="Employee_Mail" required>
                  </div>
                  <div class="field">
                     <input type="text" placeholder="Otp" name="otp" required>
                  </div>
                  <div class="field btn">
                     <div class="btn-layer"></div>
                     <input type="submit" value="Validate otp">
                  </div>
               </form>
               <script>

               </script>
            </div>
         </div>
      </div>
   </body>
</html>

我是HTML新手。

英文:

I'm doing basic login. In one HTML file I have user input email id text box, once click on send otp button that will redirect to next HTML with email and otp fields. In email field what ever user gives input in first HTML page that should automatically get into second HTML email input field text box.

Here is my first HTML page

&lt;!DOCTYPE html&gt;
{% load static %}
&lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;title&gt;Employee Login &lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;{% static &#39;style.css&#39; %}&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;
&lt;h1&gt; &lt;/h1&gt;
&lt;h2&gt; &lt;/h2&gt;
&lt;h3&gt; Employee Feedback Login&lt;/h3&gt;
&lt;/center&gt;
&lt;div class=&quot;wrapper&quot;&gt;
&lt;div class=&quot;title-text&quot;&gt;
&lt;div class=&quot;title login&quot;&gt;
Login
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-container&quot;&gt;
&lt;div class=&quot;form-inner&quot;&gt;
&lt;form action=&quot;&quot; method=&quot;post&quot; class=&quot;login&quot;&gt;
{% csrf_token %}
&lt;div class=&quot;field&quot;&gt;
&lt;input id = &quot;Employee_Mail&quot; type=&quot;text&quot; placeholder=&quot;Email Address&quot;   name=&quot;Employee_Mail&quot;  required&gt;
&lt;/div&gt;
&lt;div class=&quot;field btn&quot;&gt;
&lt;div class=&quot;btn-layer&quot;&gt;&lt;/div&gt;
&lt;input type=&quot;submit&quot; value=&quot;Send OTP&quot; &gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

and my redirect (second HTML page):

&lt;!DOCTYPE html&gt;
{% load static %}
&lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;title&gt;Employee Login &lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;{% static &#39;style.css&#39; %}&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h2&gt; &lt;/h2&gt;
&lt;h3&gt; Employee Feedback Login&lt;/h3&gt;
&lt;/center&gt;
&lt;div class=&quot;wrapper&quot;&gt;
&lt;div class=&quot;title-text&quot;&gt;
&lt;div class=&quot;title login&quot;&gt;
Login
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-container&quot;&gt;
&lt;div class=&quot;form-inner&quot;&gt;
&lt;form action=&quot;validate/&quot; method=&quot;post&quot; class=&quot;Validate OTP&quot;&gt;
{% csrf_token %}
&lt;div class=&quot;field&quot;&gt;
&lt;input type=&quot;text&quot; id= &quot;mail&quot; placeholder=&quot;Email Address&quot; name=&quot;Employee_Mail&quot; required&gt;
&lt;/div&gt;
&lt;div class=&quot;field&quot;&gt;
&lt;input type=&quot;text&quot; placeholder=&quot;Otp&quot; name=&quot;otp&quot; required&gt;
&lt;/div&gt;
&lt;div class=&quot;field btn&quot;&gt;
&lt;div class=&quot;btn-layer&quot;&gt;&lt;/div&gt;
&lt;input type=&quot;submit&quot; value=&quot;Validate otp&quot;&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;script&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

I'm new to HTML.

答案1

得分: 0

以下是翻译好的部分:

You can achieve several ways. you can do using front end side and also server side.

So, i am giving you in client side.
In client side have also many ways to achieve this (local storage, session storage, query params etc).

In First html page you can save email in local storage using javascript.

<script>
    const form = document.getElementById('form');
    const loginSubmit = (e) => {
        const email = document.getElementById("Employee_Mail").value
        localStorage.setItem('email', email)
    }

    form.addEventListener('submit', loginSubmit);
</script>

In Second HTML page, add this:

<script>
    window.onload = () => {
        document.getElementById("mail").value = localStorage.getItem("mail");
    }
</script>
英文:

You can achieve several ways. you can do using front end side and also server side.

So, i am giving you in client side.
In client side have also many ways to achieve this (local storage,session storage, query params etc).

In First html page you can save email in local storage using javascript.
`

    &lt;script&gt;
const form = document.getElementById(&#39;form&#39;);
const loginSubmit = (e) =&gt; {
const email = document.getElementById(&quot;Employee_Mail&quot;).value
localStorage.setItem(&#39;email&#39;, email)
}
form.addEventListener(&#39;submit&#39;, loginSubmit);
&lt;/script&gt;`

In Second HTML page in add this

&lt;script&gt;
window.onload = () =&gt; {
document.getElementById(&quot;mail&quot;).value = localStorage.getItem(&quot;mail&quot;);
}
&lt;/script&gt;

huangapple
  • 本文由 发表于 2023年2月6日 13:57:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75357796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定