2012-04-30 37 views
0

嗨我有一个形式在PHP中有一个动作,它会自己因此产生的结果给用户,这是我想要的,但我希望用户有选择单击一个按钮,然后将转到thank-you.php页面,将信息发送给管理员。在jquery或php中提交两次?

我一直在想这件事,但也许我会通过在另一种形式中的复杂化来改变它呢?

这是迄今为止我的表格:

<?php 
$data = array("Benalmadena"=>10,"Fuengirola"=>20,"Mijas"=>30,"La Cala"=>10,"Calahonda"=>15, 
"Marbella"=>20,"Puerto Banus"=>25,"San Pedro"=>30,"Estepona"=>40, "Nerja"=>12); 


error_reporting(E_ALL); 

if(isset($_POST['name']) && isset($_POST['to'])){ 

ini_set('date.timezone', 'Europe/Madrid'); 
$now = date("H:i"); 

$cutoff = "06:00"; 
$higherthan = "22:00"; 


$name = $_REQUEST['name']; 
$telephone = $_REQUEST['telephone']; 
$from = $_REQUEST['from']; 
$to = $_REQUEST['to']; 
$date = $_REQUEST['date']; 
$returndate = $_REQUEST['returndate']; 
$people = $_REQUEST['people']; 
$return = $_REQUEST['return']; 
$myemail = $_REQUEST['myemail']; 

include_once('includes/config.php'); 

$settingsSql = mysql_query("SELECT * FROM transfers_in WHERE location='$to' AND no_passengers='$people'"); 
$settings  = mysql_fetch_assoc($settingsSql); 

echo "From: ".$from." To: ".$settings['location']."<br />"; 
echo "Number of passengers: ".$settings['no_passengers']."<br />"; 

ini_set('date.timezone', 'Europe/Madrid'); 
$now = date("H:i"); 

$cutoff = "06:00"; 
$higherthan = "22:00"; 

echo "Time cost: ".$settings['price']." euros<br /><hr />Total: "; 



    function timeCost() { 

     $to = $_REQUEST['to']; 
     $people = $_REQUEST['people']; 
     $return = $_REQUEST['return']; 

     include_once('includes/config.php'); 

     $settingsSql = mysql_query("SELECT * FROM transfers_in WHERE location='$to' AND no_passengers='$people'"); 
     $settings  = mysql_fetch_assoc($settingsSql); 

     //echo $return; 

     if ($return == "No"){ 
      if ((strtotime($now) < strtotime($cutoff)) || (strtotime($now) > strtotime($higherthan))){ 
       return number_format($settings['price']) + 1.40; 
      } else { 
       return number_format($settings['price']) + 0.00; 
      } 
     } elseif ($return == "Yes") { 
      if ((strtotime($now) < strtotime($cutoff)) || (strtotime($now) > strtotime($higherthan))){ 
       return number_format($settings['price']) * 2 + 1.40; 
      } else { 
       return number_format($settings['price']) * 2 + 0.00; 
      } 
     } 

    } 


    session_start(); 

    $_SESSION['timeCost'] = timeCost(); 

    echo timeCost()." in euros<br /><br />"; 

    echo "<div class='fauxButton' id='sendInfo'></div>"; 


} else { 
?> 

<form method="POST" action="#" name="chooseDateForm" id="chooseDateForm"> 
      <label>Name:</label> 
      <input type="text" value="" name="name" /> 

      <label>Telephone:</label> 
      <input type="text" value="" name="telephone" /> 

      <label>Email:</label> 
      <input type="text" value="" name="myemail" /> 

      <label>From:</label> 
      <select name="from"> 
       <option selected="selected">Malaga</option> 
      </select> 
      <div class="clr"></div> 

      <label>To:</label> 
      <select name="to"> 

<?php foreach ($data as $place => $price){ 
    echo "<option>{$place}</option>\n"; 
} 
echo '</select> 
      <div class="clr"></div> 

      <label>Date:</label> 
      <input type="text" value="dd/mm/yyyy" id="date" name="date" class="date-pick" /> 
      <span id="calendar"></span> 

      <div id="return-journey"> 
       <label>Return Date:</label> 
       <input type="text" value="dd/mm/yyyy" id="returndate" name="returndate" class="date-pick" /> 
       <span id="calendar"></span> 
      </div> 

      <label>Number of people:</label> 
      <select id="people" name="people"> 
       <option value="4">4</option> 
       <option value="6">6</option> 
       <option value="8">8</option> 
      </select> 
      <div class="clr"></div> 

      <div id="return"> 
       <label>Is this a return<br />journey?</label> 
       <div class="clr"></div> 
       <div id="radio-buttons"> 
        <input type="radio" name="return" value="Yes" class="radio returning" />Yes<br /> 
        <input type="radio" name="return" value="No" class="radio" checked />No 
       </div> 
      </div> 
      <div class="clr"></div> 


      <input type="submit" name="submit" class="fauxButton" />    

     </form>'; 
} 
?> 

我加了这一点:

<div class='fauxButton' id='sendInfo'></div> 

但形式已经送到我不能改变在jQuery的动作,我不知道关于jQuery或PHP,所以如果任何人可以建议/帮助请做。

感谢

+0

为什么是“谢谢”一个不能使用此页面?如果帖子被设置并且所有的验证都可以,你可以打印出“tahnk you”而不是form。如果不验证,则打印出表单/错误。 – sed

+0

我同意@Qmal,好像你在这里有一个额外的步骤。您的目的是不直接发送到感谢页面并将信息发送给管理员? –

回答

0

您可以将它添加到您的按钮:

OnClick="location.href='http://www.YourUrlGoesHere.com'" 
//So it will look like this.. 
echo "<div class='fauxButton' id='sendInfo' OnClick=\"location.href='http://www.YourUrlGoesHere.com'\"></div>"