doumibi6899 2013-03-29 15:24
浏览 80

表单上的两个提交按钮每次重定向到点击不同的页面?

I admit I'm over my head on this. I'm running out of time as I need this page to work by Monday and I'm getting desperate; I've spend the last week googling and combing through stackoverflow answers and I still can't figure out how to get this to work.

I have 1 form with two submit buttons at the bottom, HOLD RESERVATION and BOOK NOW. Each button needs to submit the form data (just in an email, nothing fancy), then redirect either to a reservation confirmation static html page, or to my booking page.

I've tried this, which redirects nicely, but doesn't email me the form data:

<input type="submit" onclick="var e = document.getElementById('mpNOV'); e.submit(); e.action='mp-NOVconfirm.shtml';" value="Hold my reservation" class="submit"></td>
<td width="45%" style="padding-top:10px; padding-bottom:10px; border-top: 1px solid #6f3957;">
<input type="submit" onclick="var e = document.getElementById('mpNOV'); e.submit(); e.action='../../index.shtml';" value="Book Now!" class="submit">

I've tried having my FORM ACTION="external.php" with this being the php code (based on php code I used for a different form submit):

<?php
if($_SERVER['REQUEST_METHOD'] === 'POST')
 {
 if(isset($_POST['Reservation']))
 {
 $subject = 'New Machu Picchu RESERVATION - November'; 
 $emailadd = 'jodi@happywivestravel.com'; 
 $url = 'http://www.happywivestravel.com/tour/machupicchu/mp-NOVconfirm.shtml'; 
 $req = '0';
 $text = "Results from form:

"; 
 $space = ' ';
 $line = ' 
 ';
 foreach ($_POST as $key => $value)
 {
  if ($req == '1')
  {
  if ($value == '')
  {echo "$key is empty";die;}
 }
 $j = strlen($key);
 if ($j >= 20)
 {echo "Name of form element $key cannot be longer than 20 characters";die;}
 $j = 20 - $j;
 for ($i = 1; $i <= $j; $i++)
 {$space .= ' ';}
 $value = str_replace('
', "$line", $value);
 $conc = "{$key}:$space{$value}$line";
 $text .= $conc;
 $space = ' ';
 }
 mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
 echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}

if(isset($_POST['Book']))
{
 $subject = 'New Machu Picchu BOOKING - November'; 
 $emailadd = 'jodi@happywivestravel.com'; 
 $url = 'http://www.happywivestravel.com/';
 $req = '0'; 
 $text = "Results from form:

"; 
 $space = ' ';
 $line = ' 
 ';
 foreach ($_POST as $key => $value)
 {
  if ($req == '1')
  {
  if ($value == '')
  {echo "$key is empty";die;}
 }
 $j = strlen($key);
 if ($j >= 20)
 {echo "Name of form element $key cannot be longer than 20 characters";die;}
 $j = 20 - $j;
 for ($i = 1; $i <= $j; $i++)
 {$space .= ' ';}
 $value = str_replace('
', "$line", $value);
 $conc = "{$key}:$space{$value}$line";
 $text .= $conc;
 $space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
}
?>

But there must be something I did wrong here, because nothing happens when I click the submit button(s). No redirect, no form data emailed.

I originally wanted to get this function to work with a captcha script, but I've had to scrap that for now. I just need to get these submit buttons working properly asap.

I know next to nothing about php, and I'm very green with javascript (I'm learning as I go here). I really would appreciate any help here. THANK YOU!!

  • 写回答

4条回答 默认 最新

  • duanjia2772 2013-03-29 15:39
    关注

    Why don't you but the buttons in a form tag? And navigate with that?

    <form id="formid" action="link" method="post">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)