gpt4 book ai didi

php - PHP 表单提交页面跳转

转载 作者:行者123 更新时间:2023-11-29 03:00:40 25 4
gpt4 key购买 nike

我正在单页机网站上处理 php 表单。我遇到了两个问题。首先是表单在提交时跳转到页面顶部。我尝试了几种不同的方法来防止这种情况发生,但似乎都没有效果。第二个是表单 session 保持启动状态,如果用户按 ctrl-r,则会导致我的数据库中重新提交空白。

如果有人知道如何取消提交时的页面跳转,那将是非常棒的。

谢谢,

<?php
if(isset($_POST['add']))
{
$dbhost = 'XXX';
$dbuser = 'XXX';
$dbpass = 'XXX';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
$form_name = addslashes ($_POST['form_name']);
$form_email = addslashes ($_POST['form_email']);
$form_phone = addslashes ($_POST['form_phone']);
$form_linkedin = addslashes ($_POST['form_linkedin']);

$form_q1 = addslashes ($_POST['form_q1']);
$form_q2 = addslashes ($_POST['form_q2']);
$form_q3 = addslashes ($_POST['form_q3']);
$form_q4 = addslashes ($_POST['form_q4']);
$form_q5 = addslashes ($_POST['form_q5']);
}
else
{

$form_name = $_POST['form_name'];
$form_email = $_POST['form_email'];
$form_phone = $_POST['form_phone'];
$form_linkedin = $_POST['form_linkedin'];

$form_q1 = $_POST['form_q1'];
$form_q2 = $_POST['form_q2'];
$form_q3 = $_POST['form_q3'];
$form_q4 = $_POST['form_q4'];
$form_q5 = $_POST['form_q5'];
}

$sql = "INSERT INTO XXX".
"(form_name, form_email, form_phone, form_linkedin, form_q1, form_q2, form_q3, form_q4, form_q5) ".
"VALUES('$form_name','$form_email','$form_phone', '$form_linkedin', '$form_q1', '$form_q2', '$form_q3', '$form_q4', NOW())";
mysql_select_db('XXX');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die("<section id='thank_you'><h1>SOMETHING WENT WRONG</h1><p class='about_body_txt'>Click <a href='XXX'>here</a> to resubmit</p></section>");
}
echo("<section id='thank_you'><h1>THANK YOU</h1><p class='about_body_txt'>Selected participants will be notified by July 8, 2014. Click <a href='XXX'>here</a> to return to the main site.</p></section>");
mysql_close($conn);
}
else
{
?>
<form id="gfbm_form" class="theForm" role="form" autocomplete="off" method="POST">

<h2>APPLICATIONS DUE<br/>
<span class="medium_txt">THURSDAY, JULY 3RD AT 5PM, EST.</span></h2>



<div class="application">

<ul>
<li class="small_field">
<span><label class="label_field">Name</label></span>
<br/>
<input id="form_name" class="name input_field" type="text" name="form_name" />
</li>

<li class="small_field">
<span><label class="label_field">Email</label></span>
<br/>
<input id="form_email" class="email input_field" type="text" name="form_email" />
</li>

<li class="small_field_2">
<span><label class="label_field">Phone</label></span>
<br/>
<input id="form_phone" class="phone input_field" type="text" name="form_phone" />
</li>


<li class="small_field_2">
<span><label class="label_field">LinkedIn</label></span>
<br/>
<input id="form_linkedin" class="linkedin input_field" type="text" name="form_linkedin" />
</li>


<li class="essay_question">
<span><label class="label_field">QUESTION 1</label></span>
<br/>
<textarea id="form_q1" class="q1 input_field_big" type="text" name="form_q1"></textarea>
</li>

<li class="essay_question">
<span><label class="label_field">QUESTION 2</label></span>
<br/>
<textarea id="form_q2" class="q2 input_field_big" type="text" name="form_q2"></textarea>
</li>


<li class="essay_question">
<span><label class="label_field">QUESTION 3</label></span>
<br/>
<textarea id="form_q3" class="q3 input_field_big" type="text" name="form_q3"></textarea>
</li>


<li class="essay_question">
<span><label class="label_field">QUESTION 4</label></span>
<br/>
<textarea id="form_q4" class="q4 input_field_big" type="text" name="form_q4"></textarea>
</li>
</ul>



<input type="checkbox" required id="checkbox-2-1" class="regular-checkbox big-checkbox" />
<label class="check_text">
<p>YES, I'LL BE AVAILABLE FOR ALL OF THOSE DATES.</p>
</label>


<input type="checkbox" required id="checkbox-2-2" />
<label class="check_text">
<p>I have read and understand the terms and conditions.</p>
</label>



<input name="add" type="submit" class="submit btn btn-default" id='submit' value="APPLY">




</form>

最佳答案

submit 提交页面并重新加载它,使您再次位于顶部。您可以创建一个 HTML anchor 并使用 onload javascript 事件或其他东西触发它以将用户移回相同的位置,但仅此而已。

关于php - PHP 表单提交页面跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24172902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com