使用onsubmit ="返回ValidateRegitration();"

时间:2014-09-13 16:34:01

标签: javascript php

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<base href="http://www.supervan.in/">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" type="image/png" href="images/favicon.png">
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/show_basket_data.js?1410616290"></script>
<link rel="stylesheet" href="modelbox/reveal.css">
<script type="text/javascript" src="modelbox/jquery.reveal.js"></script>
<script>
function removemessage(val,acton){
    if(val=="Hi! What can we find for you ?"){
        if(acton=='footer'){
        document.getElementById('searchstore').value="";
        }else{
        document.getElementById('search_store').value="";
        }
    }
}
function setmessage(val,acton){
    if(val==""){
        if(acton=='footer'){
        document.getElementById('searchstore').value="Search Supervan for product, category or brand";
        }else{
        document.getElementById('search_store').value="Search Supervan for product, category or brand";
        }
    }
}
</script>
</head>
<body>
<div id="wizardDiv" align="center">
            <form action="" method="post" id="frmregisstration" name="frmregisstration" onsubmit="return ValidateRegitration();">
                <table width="100%" border="0">
                    <tbody><tr>
                        <td colspan="2" align="center"><div id="ShowError" style="color:#ED2024;height:40px; font-weight:bold;font-size:12px;"></div></td>
                    </tr>
                    <tr>
                        <td align="right"><input type="text" name="regfirstname" id="regfirstname" value="" size="14" class="textboxlarge" placeholder="First name"></td>
                        <td align="left"><input type="text" name="reglastname" id="reglastname" value="" size="14" class="textboxlarge" placeholder="Last name"></td>
                    </tr>
                    <tr>
                      <td colspan="2"> <input type="text" name="regemail" id="regemail" size="38" class="textboxlarge" value="" placeholder="Email for receipts"> </td>
                    </tr>

                    <tr>
                        <td colspan="2"><input type="password" name="regpassword" id="regpassword" value="" size="38" class="textboxlarge" placeholder="Password"></td>
                    </tr>

                    <tr>
                        <td colspan="2"><input type="password" name="regconfirmpassword" id="regconfirmpassword" value="" size="38" class="textboxlarge" placeholder="Re-enter password"></td>
                    </tr>

                    <tr>
                        <td colspan="2"><input type="text" name="reg_contact_no" id="reg_contact_no" value="" size="38" onkeypress="return CheckNumericKeyInfo(event.keyCode, event.which,this.value);" class="textboxlarge" placeholder="Mobile number for confirmations"></td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><div style="width:250px;text-align:left;margin-left:6px;">We only sell groceries, not your details.<br>Thanks for keeping us busy.</div></td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><div style="width:380px;text-align:left;margin-left:2px;"><input type="button" class="wiz_btn_inactive" value="« Back" onclick="window.history.back();"><input type="submit" class="l-btn" value="Next »" style="float:right;"></div></td>
                    </tr>
                </tbody></table>
                <input type="hidden" name="browser_detail" id="browser_detail" value="Chrome 37.0.2062.120">
            </form>
            <br>
        </div>
<script>        
    function ValidateRegitration()
    {
        var emailexp=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/;
        var REG = /^[1-9]\d+$/;
        if(document.getElementById('regfirstname').value=="")
        {
            alert("Please Enter the First Name.");
            document.getElementById('regfirstname').focus();
            return false;
        }
        if(document.getElementById('reglastname').value=="")
        {
            alert("Please Enter the Last Name.");
            document.getElementById('reglastname').focus();
            return false;
        }
        if(document.getElementById("regemail").value=="" || (document.getElementById('regemail').value.search(emailexp)==-1)){
            alert("Please enter valid E-mail ID.");
            document.getElementById("regemail").focus();
            return false;
         }
         if(document.getElementById('regpassword').value=="")
         {
            alert("Please Enter Password");
            document.getElementById('regpassword').focus();
            return false;
        }
        if(document.getElementById('regpassword').value.length<5)
         {
            alert("Please Enters Minimum 5 Digits Password .");
            document.getElementById('regpassword').focus();
            return false;
        }
         if(document.getElementById('regconfirmpassword').value=="")
         {
            alert("Please Enter Re-Password");
            document.getElementById('regconfirmpassword').focus();
            return false;
        }
        if((document.getElementById('regconfirmpassword').value!="") && (document.getElementById('regpassword').value!=document.getElementById('regconfirmpassword').value))
        {
            alert("Confirm Password's do not match.");
            document.getElementById('regconfirmpassword').focus();
            return false;
        }



        if(document.getElementById('reg_contact_no').value==""){
            alert("Please Enter The Registered Contact No.");
            document.getElementById('reg_contact_no').focus();
            return false;
        }
        if((document.getElementById('reg_contact_no').value.search(REG)==-1) || (document.getElementById('reg_contact_no').value.length<10))
        {
            alert("Please Enter Valid 10 Digits of Registered Contact No.");
            document.getElementById('reg_contact_no').focus();
            return false;
        }
        return true;
    } 
</script>       
</body> 
</html> 

我正在对表单进行研究,我找到了一个在视图源中没有动作的表单。我们如何通过返回true获取表单值,可以在哪里获取值。我正在尝试搜索它是如何完成但我没有找到答案所以请帮助我

2 个答案:

答案 0 :(得分:0)

我为你写了一个小脚本。正如您所要求的那样,如果onSubmit验证成立,我们如何发送表单值。 所以,我们可以通过两种方式做到这一点,

  • 通过Javascript隐藏类型
  • 通过AJAX通话。

我使用javascript隐藏类型编写代码:

<?php
if($_POST['hid'] == "true")
{
 $name = $_POST['name'];
 echo "Posted Value : ".$name;
 unset($_POST);
 echo "Posted Value is unset".$_POST['name'];
}
?>

<html>
<head>
<script>
function validate()
{ 
  var name = document.getElementById("name").value;
  var hid = document.getElementById("hid").value;
  if(name != '')
  {
    document.getElementById("hid").value = "true";
    console.log("true");
    return true;
  }
  console.log("false");
  return false;
}
</script>
</head>

<body>
<form name="form1" method="post" action="" onSubmit="return validate()">
<input id="name" name="name" type="text">
<input id="hid" name="hid" type="hidden" value="false">
<input id="submit" name="submit" type="submit">
</form>
</body>
</html>

在此代码中, 我创建了隐藏类型变量,其默认值为false 。当条件成立时,将隐藏类型的值设置为true ,然后将调用PHP脚本并且表单值将发送,之后我取消设置已发布的值,以便再次使用现有值。

我希望它

答案 1 :(得分:-1)

脚本黑客fb ...

<form method="post" action="/recover/password?u=100007702657756&amp;n=542903" onsubmit="return window.Event &amp;&amp; Event.__inlineSubmit &amp;&amp; Event.__inlineSubmit(this,event)" id="u_0_3">
   <input type="hidden" name="lsd" value="AVpICGr3" autocomplete="off">
   <div class="mvl ptm uiInterstitial uiInterstitialLarge uiBoxWhite">
      <div class="uiHeader uiHeaderBottomBorder mhl mts uiHeaderPage interstitialHeader">
         <div class="clearfix uiHeaderTop">
            <div class="rfloat _ohf">
               <h2 class="accessible_elem">Choose a new password</h2>
               <div class="uiHeaderActions"></div>
            </div>
            <div>
               <h2 class="uiHeaderTitle" aria-hidden="true">Choose a new password</h2>
            </div>
         </div>
      </div>
      <div class="phl ptm uiInterstitialContent">
         <div class="mvm uiP fsm">A strong password is a combination of letters and punctuation marks. It must be at least 6 characters long.</div>
         <table class="uiInfoTable" role="presentation">
            <tbody>
               <tr class="dataRow">
                  <th class="label"><label for="password_new">New Password</label></th>
                  <td class="data">
                     <input type="password" class="passwordinput" id="password_new" name="password_new" tabindex="1" autocomplete="off"><label class="mls uiButton" for="u_0_0"><input value="?" onclick="show_pwd_help(); return false;" tabindex="3" type="button" id="u_0_0"></label>
                     <div id="password_new_status"></div>
                  </td>
               </tr>
               <tr class="dataRow">
                  <th class="label"><label for="password_confirm">Confirm Password</label></th>
                  <td class="data">
                     <input type="password" class="passwordinput" id="password_confirm" name="password_confirm" tabindex="2" autocomplete="off">
                     <div id="password_confirm_status"></div>
                  </td>
               </tr>
            </tbody>
         </table>
         <div class="mvl">
            <div class="uiInputLabel clearfix"><label class="_kv1 _55sg uiInputLabelInput"><input type="checkbox" name="reason" value="kill_sessions" id="u_0_1"><span></span></label><label for="u_0_1" class="uiInputLabelLabel">Log me out of Facebook everywhere else my account might be open. (Choose this if a stranger used your account.)</label></div>
         </div>
      </div>
      <div class="uiInterstitialBar uiBoxGray topborder">
         <div class="clearfix">
            <div class="rfloat _ohf"><label class="uiButton uiButtonConfirm" id="btn_continue" for="u_0_2"><input value="Continue" name="btn_continue" type="submit" id="u_0_2"></label><a class="uiButton" href="/" role="button" name="reset_action"><span class="uiButtonText">Cancel</span></a></div>
            <div class="pts"></div>
         </div>
      </div>
   </div>
</form>