English 中文(简体)
提交文件失败
原标题:Form Submission failed
  • 时间:2022-10-14 06:10:02
  •  标签:
  • javascript

在提交表格时,我有一个问题,它给我留下的错误,即“有效”是指没有界定的。

在此之前,它一直在工作。

It is loan application in which I have to send an email once user submit form with correct details and also generate random 4 digit no which will be in email which user will receive

<script src="https://smtpjs.com/v3/smtp.js">
## Heading ##
    function validateForm() {
      let name = document.forms["myForm"]["fullName"].value;
      let email = document.forms["myForm"]["email"].value;
      let pan = document.forms["myForm"]["pan"].value;
      let lamount = document.forms["myForm"]["flamnt"].value;
      let regName = /d+$/g;
      let regEmail = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/g;
      let regPan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

      //captcha validation
      let input_val = document.getElementById( input_val );
       
      let num1 = document.getElementById( num1 );
      let num2 = document.getElementById( num2 );
      const mybtn = document.getElementById( btn );
       //returns a random integer from 0to9
         num1.innerText = Math.floor(Math.random() * 10);
         num2.innerText = Math.floor(Math.random() * 10);
         let number1 = num1.innerText;
         let number2 = num2.innerText;
        
  

    
      mybtn.addEventListener("click", () => {
        //
        let sum_result = parseInt(number1) + parseInt(number2);

        let res = parseInt(input_val.value);

        if (res == sum_result) {
          alert("correct");
        }
        else {
          alert("Incorrect")
        }
          window.location.reload();
      });

      if (name == "" || regName.test(name)) {
        alert("Name must be filled out");
        return false;
      }

      if (email == "" || !regEmail.test(email)) {
        alert("Please enter a valid e-mail address.");
        return false;
      }

      if (pan == "" || !regPan.test(pan)) {
        alert("Please enter a valid PAN no.");
        return false;
      }

      //OTP generation

      const generateOtp = () =>{
        let otp = "";

        for(let i=0 ; i < 4 ; i++){
          otp += Math.floor(Math.random() * 10);
        }
        //if we write return otp directly then this will return otp in string
        return Number(otp); //this will return otp as number.
      };
      console.log("OTP:", generateOtp());

    }

    //sending an email
    // function sendEmail() {
    //   Email.send({
    //     Host: "smtp.gmail.com",
    //     Username: "[email protected]",
    //     Password: "....",
    //     To: document.getElementById("email").value,
    //     From: "[email protected]",
    //     Subject: "Thank you for Inquiry",
    //     Body: "Well that was easy!!",
    //   })
    //     .then(function (message) {
    //       alert("mail sent successfully")
    //     });
    // }

  </script>
</head>

<body>
  <div class="form-container">
    <h1>Loan Application Form</h1>
    <form name="myForm" method="post" action="thankyou.html" onsubmit="validateForm();">
      <div class="formdesign" id="name">
        Full Name:<input type="text" class="form-control" placeholder="Enter your fullname" name="fullName"><span
          class="formerror"></span>
      </div>

      <div class="formdesign" id="email">
        Email:<input type="email" class="form-control" placeholder="Enter email" name="email"><span
          class="formerror"></span>
      </div>

      <div class="formdesign" id="panno">
        PAN No:<input type="text" class="form-control" placeholder="Like BBHPM5672K" name="pan" maxlength="10"><span
          class="formerror"></span>
      </div>

      <div class="formdesign" id="lamount">
        Loan Amount:<input type="number" class="form-control" placeholder="Enter loan amount" name="flamnt"><span
          class="formerror"></span>
      </div>

      <div class="formdesign">

        Enter Captcha:<input type="text" placeholder="enter captcha" class="form-control" id="input_val" />
        <p id="operation"><span id="num1">1</span> + <span id="num2">2</span></p>
        <button id="bttn" class="captcha-refresh"><i class="fa fa-refresh"></i>Refresh</button>
      </div>

      <input id="btn" class="button" type="submit" value="Submit">
      <input class="button" type="reset" value="Reset">
    </form>
问题回答

你有许多问题

  1. 页: 1

  2. 请试图利用狙击手[和设计;]并删除“此处的成像法”和编号# Heading#

  3. 你们需要利用提交活动,例如防止提交文件。 我将名称改为“米Form”,改为“米Form”,表格不需要名称。

  4. 你正在增加活动听众。

  5. 你没有履行复习职能。

在这方面,我相信你需要做些什么。

const generateOtp = () => {
  let otp = "";

  for (let i = 0; i < 4; i++) {
    otp += Math.floor(Math.random() * 10);
  }
  //if we write return otp directly then this will return otp in string
  return Number(otp); //this will return otp as number.
};

document.getElementById( bttn ).addEventListener("click", e => {
  e.preventDefault();
  let num1 = document.getElementById( num1 );
  let num2 = document.getElementById( num2 );

  //returns a random integer from 0to9
  num1.innerText = Math.floor(Math.random() * 10);
  num2.innerText = Math.floor(Math.random() * 10);
})


document.getElementById("myForm").addEventListener("submit", (e) => {
  const form = e.target;
  let name = form["fullName"].value;
  let email = form["email"].value;
  let pan = form["pan"].value;
  let lamount = form["flamnt"].value;
  let regName = /d+$/g;
  let regEmail = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/g;
  let regPan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

  //captcha validation
  let input_val = document.getElementById( input_val );

  let num1 = document.getElementById( num1 );
  let num2 = document.getElementById( num2 );
  let number1 = num1.innerText;
  let number2 = num2.innerText;

  let errors = [];

  let sum_result = parseInt(number1) + parseInt(number2);

  let res = parseInt(input_val.value);

  if (res != sum_result) errors.push("Sum not correct");

  if (name == "" || regName.test(name)) errors.push("Name must be filled out");
  if (email == "" || !regEmail.test(email)) errors.push("Please enter a valid e-mail address.");
  if (pan == "" || !regPan.test(pan)) errors.push("Please enter a valid PAN no.");

  if (errors) {
    alert(errors.join("
"));
    e.preventDefault();
    return
  }
  //OTP generation
  console.log("OTP:", generateOtp()); // not sure what you want with this
  // sendEmail()
})

//sending an email
// function sendEmail() {
//   Email.send({
//     Host: "smtp.gmail.com",
//     Username: "[email protected]",
//     Password: "...",
//     To: document.getElementById("email").value,
//     From: "[email protected]",
//     Subject: "Thank you for Inquiry",
//     Body: "Well that was easy!!",
//   })
//     .then(function (message) {
//       alert("mail sent successfully")
//     });
// }
<script src="https://smtpjs.com/v3/smtp.js"></script>
<div class="form-container">
  <h1>Loan Application Form</h1>
  <form id="myForm" method="post" action="thankyou.html">
    <div class="formdesign" id="name">
      Full Name:<input type="text" class="form-control" placeholder="Enter your fullname" name="fullName"><span class="formerror"></span>
    </div>

    <div class="formdesign" id="email">
      Email:<input type="email" class="form-control" placeholder="Enter email" name="email"><span class="formerror"></span>
    </div>

    <div class="formdesign" id="panno">
      PAN No:<input type="text" class="form-control" placeholder="Like BBHPM5672K" name="pan" maxlength="10"><span class="formerror"></span>
    </div>

    <div class="formdesign" id="lamount">
      Loan Amount:<input type="number" class="form-control" placeholder="Enter loan amount" name="flamnt"><span class="formerror"></span>
    </div>

    <div class="formdesign">

      Enter Captcha:<input type="text" placeholder="enter captcha" class="form-control" id="input_val" />
      <p id="operation"><span id="num1">1</span> + <span id="num2">2</span></p>
      <button id="bttn" class="captcha-refresh"><i class="fa fa-refresh"></i>Refresh</button>
    </div>

    <input id="btn" class="button" type="submit" value="Submit">
    <input class="button" type="reset" value="Reset">
  </form>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签