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:\n\n";
$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('\n', "$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:\n\n";
$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('\n', "$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!!