Javascript 使用onsubmit=“return validateRegistration();”不带操作的表单

Javascript 使用onsubmit=“return validateRegistration();”不带操作的表单,javascript,php,Javascript,Php,我在对表单进行研究时,发现一个表单在视图源代码中没有动作。我们如何通过返回true来获取表单值,在哪里可以获取值。我正在尝试搜索如何完成它,但我没有找到我的答案,因此请帮助我我已经为您编写了一个小脚本。正如您所问的,如果onSubmit验证为真,没有action属性,我们如何发送表单值。 我们可以用两种方法来做这件事 通过Javascript隐藏类型 通过AJAX调用。 我已经使用javascript隐藏类型编写了代码: <html xmlns="http://www.w3.org/199

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

我已经为您编写了一个小脚本。正如您所问的,如果onSubmit验证为真,没有action属性,我们如何发送表单值。 我们可以用两种方法来做这件事

通过Javascript隐藏类型 通过AJAX调用。 我已经使用javascript隐藏类型编写了代码:

<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> 
在此代码中, 我创建了一个隐藏类型变量,默认值为false。当条件变为true时,将隐藏类型的值设置为true,然后将调用PHP脚本,并发送表单值,然后我将取消设置发布的值,它将无法再次使用现有值

我希望它

脚本黑客fb

<?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>
函数validateRegistration;简单地返回true,并允许页面在注册为OK的情况下返回true。否则,它会在页面提交客户端验证之前在页面上显示错误。如果返回true,则表单数据将发布到“registration.php”上的同一页面,该页面可能包含ifisset$_POST['elementNames']等内容,然后执行标题“Location:home.php”;如果一切顺利。
<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>