验证表单+重定向

Validation Form + Redirect

本文关键字:重定向 表单 验证      更新时间:2023-09-26

我正在尝试在提交后向表单添加重定向页面。

目前,在提交表单后,它会显示一条小短信"谢谢你的发送",但我希望它重定向到另一个页面。是否有方法将重定向函数添加到验证脚本或直接在表单中?

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Test</title>
            <link href="styles.css" rel="stylesheet" type="text/css">
                <script type="text/javascript">
                function validateForm() {
                var x=document.forms["myForm"]["FirstName"].value;
                if (x==null || x=="")
                  {
                  alert("Name is missing");
                  return false;
                  }
                var y=document.forms["myForm"]["MobilePhone"].value;
                if (y==null || y=="") {
                  alert("Mobile is missing");
                  return false;
                  }
                    var y=document.forms["myForm"]["Email"].value;
                if (y==null || y=="") {
                  alert("Mail is missing");
                  return false;
                  }
                    }
            </script>
        </head>
        <body>
            <div id="background">
                <div id="Background">
                    <div id="contact">
                    <form name="myForm" method="post" accept-charset="UTF-8" action="http://clients.frontask.co.il/12137/Pages/Utilities/WebToLead.aspx?type=form" onsubmit="return validateForm()">
                    <table border="0">
                        <tbody>
                        <tr>
                        <td>
                        <input type="text" name="FirstName"/>
                        </td>
                        <td style="padding-right: 94px;">
                        <input type="text" name="AccountName" />
                        </td>
                        </tr>
                        <tr>
                        <td>
                        <input type="text" name="MobilePhone"/>
                        </td>
                        <td style="padding-right: 94px;">
                        <input type="text" name="Title" />
                        </td>
                        </tr>
                        <tr>
                        <td>
                        <input type="text" name="Email" />
                        </td>
                        <td style="padding-right: 94px;padding-top: 11px;">
                            <select name="Address">
                              <option>1</option>
                              <option>2</option>
                              <option>3</option>
                              <option>4</option>
                              <option>5</option>
                              <option>6</option>
                            </select>
                        </td>
                        </tr>
                            <tr>
                        <td style="padding-top:5px;">
                        <input type="checkbox" name="MailingList" checked="checked"/>
                        </td>
                        <td style="padding-right: 94px;padding-top: 11px;">
                        <input type="submit" value="send" />
                        </td>
                        </tr>
                        </tbody>
                        </table>

                    <input type="hidden" name="SystemID" value="2e1a82a2-350f-44fe-b571-0fc344f12fbf" />
    <input type="hidden" name="ProcessDefinitionStepID" value="PP60400279_0B8F_41F8_ABCC_15834568F4BE" />
    <input type="hidden" name="RedirectTo" value="" />
    <input name="enc" type="hidden" value="&#9760;" />
    <input type="hidden" name="UpdateExistingDetails" value="false" />
    <input type="hidden" name="ContactTypes" value="PM8BA799EF_23FF_4679_8484_D603E2DC8BB0" />

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

提交后,使用以下代码重定向页面。

window.location.href = 'give the url which you want to redirect';

将其添加到validateForm() 的末尾

alert("thank you for sending");
window.location.href = 'give the url which you want to redirect';