表单-提交后返回值为空



im试图将表单输入值填充到一个新的弹出窗口中,为此im使用window.open方法。然而,我设法获得了弹出窗口的宽度,输入没有通过,页面返回时没有值。请告知如何解决此问题。提前谢谢。我是网络开发的新手。

脚本

function validate(){ <!-- HTML form validation done by JavaScript.  -->
<!-- variable object used to represent the questions in the form  -->
var x1=document.getElementById("text1");
var x2=document.getElementById("text2");
var x3=document.getElementById("hobbies");
var x4=document.getElementById("Gender");

<!-- if used to verify if no information given the the alert will pop up upon submission -->
if (x1.value == "" || x2.value == "" || x3.value == "" || x4.value == "") 
{
alert("No blank values allowed")
return false;
}
else
{
window.open('https://quiet-odyssey-258110.appspot.com/'+self.location,'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
}
}
</script>

形成

<form onsubmit="return validate()">
<!-- label used to tag the field name -->
<label>Full Name : </label>
<input type= "text" id="text1" name= "text1" placeholder="Enter your Full Name here..."><br>
<label>Email address : </label>
<input type= "email" id="text2" name= "email" placeholder="Enter your Email Address here..." ><br><br>
<label>Hobbies : </label><br><br>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Reading"/>Reading<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Painting"/>Painting<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Traveling"/>Traveling<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Baking"/>Baking<br/><br/>
<label>Gender</label><br><br>  <!-- drop donw list has been used to choose gender and locations -->
<input type="radio" id="Gender" name="gender" value="Male" > Male<br>
<input type="radio" id="Gender" name="gender" value="Female"> Female<br>
</select><br>


</hr>
<button type="submit" class="registerbtn" >Register</button>
<button type="reset" class="Reset">Reset</button>

</form>

PHP

Congratulations !!!<br/><br/>
Your Full Name : <?php echo $_GET["text1"]; ?><br/>
Your Email address : <?php echo $_GET["email"]; ?><br/>
Your Hobbies : <?php foreach($_GET['hobbies'] as $selected){
echo $selected.", ";};?><br/>
Your Gender : <?php echo $_GET["gender"]; ?><br/>

您错过了在URL中添加值。

window.open('https://quiet-odyssey-258110.appspot.com/?text1='+ x1 +'&email='+x2+',"我赢了",'左=20,顶=20,宽=500,高=500,工具栏=1,可调整大小=0'(;

您试图用$_GET["text1"]获取参数,但没有在window.openurl查询字符串中传递它们。要在$_GET["text1"]中有内容,您应该在url 中有类似?text1=some_value的内容

您没有定义表单提交的方法。首先,您在HTML代码中提到了Your方法。

<form onsubmit="return validate()" method="post" action="">
<!-- label used to tag the field name -->
<label>Full Name : </label>
<input type= "text" id="text1" name= "text1" placeholder="Enter your Full Name here..."><br>
<label>Email address : </label>
<input type= "email" id="text2" name= "email" placeholder="Enter your Email Address here..." ><br><br>
<label>Hobbies : </label><br><br>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Reading"/>Reading<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Painting"/>Painting<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Traveling"/>Traveling<br/>
<input type="checkbox" id="hobbies" name="hobbies[]" value="Baking"/>Baking<br/><br/>
<label>Gender</label><br><br>  <!-- drop donw list has been used to choose gender and locations -->
<input type="radio" id="Gender" name="gender" value="Male" > Male<br>
<input type="radio"
</hr>
<button type="submit" class="registerbtn" >Register</button>
<button type="reset" class="Reset">Reset</button>   
</form>

如果你的方法GET然后得到结果SomethingLike:

Your Full Name : <?php echo $_GET["text1"]; ?><br/>
Your Email address : <?php echo $_GET["email"]; ?><br/>
Your Hobbies : <?php foreach($_GET['hobbies'] as $selected){
echo $selected.", ";};?><br/>
Your Gender : <?php echo $_GET["gender"]; ?><br/>

如果你的方法POST然后得到类似的结果:

Your Full Name : <?php echo $_POST["text1"]; ?><br/>
Your Email address : <?php echo $_POST["email"]; ?><br/>
Your Hobbies : <?php foreach($_POST['hobbies'] as $selected){
echo $selected.", ";};?><br/>
Your Gender : <?php echo $_POST["gender"]; ?><br/>

如果你使用JavaScript,那么你的后回答变量应该像这个一样通过URL

window.location.href =
URL?text1="+text1+"&email="+email+"&hobbies="+hobbies+"+&gender="+gender+"

最新更新