Jump to content

Help with Form - can't get option values passed


oavs

Recommended Posts

Hi

I am grateful that you are reading this, so let me thank you first.

 

I have form which works fine except the select field which has some options and the date select . When I receive my email I get all the fields except the option field. Not sure how to get the date fields yet.

 

I hope you can help.

 

This is the form:

<script>
// <![CDATA[
jQuery(document).ready(function(){
$('#contactform').submit(function(){				  
	var action = $(this).attr('action');
	$.post(action, { 
		name: $('#name').val(),
		email: $('#email').val(),
		phone: $('#phone').val(),
		enquiries: $('#enquiries').val(),
		message: $('#message').val()
	},
		function(data){
			$('#contactform #submit').attr('disabled','');
			$('.response').remove();
			$('#contactform').before('<p class="response">'+data+'</p>');
			$('.response').slideDown();
			if(data=='Message sent!') $('#contactform').slideUp();
		}
	); 
	return false;
});
});
// ]]>
</script>



<form action="send.php" method="post" id="contactform">
          <ol>
            <li>
              <label for="name">First Name <span class="red">*</span></label>
              <input id="name" name="name" class="text" />
            </li>
            <li>
              <label for="email">Your email <span class="red">*</span></label>
              <input id="email" name="email" class="text" />
            </li>
            <li>
              <label for="phone">Phone Contact <span class="red">*</span></label>
              <input id="phone" name="phone" class="text" />
            </li>
            <li>
              <label for="enquiries">Enquiries <span class="red">*</span></label>
              <select name="enquiries" >
                <option value="Not Selected">--- Please Select ----</option>
                <option value="Bookings">Bookings</option>
                <option value="General Enquiry">General Enquiry</option>
                <option value="Expander">Expander</option>
                <option value="Swan">Swan</option>
              </select>
            </li>
            <li>
              <label for="date-from">Date <span class="red">*</span></label>
              <div style="float: left;">
                <div style="float: left; padding-right: 3px; line-height: 18px;">from:</div>
                           
                <div style="float: left;">
<?php		
  $thisweek = date('W');
	$thisyear = date('Y');

	$dayTimes = getDaysInWeek($thisweek, $thisyear);
	//----------------------------------------

	$date1 = date('Y-m-d', $dayTimes[0]);
	$date2 = date('Y-m-d', $dayTimes[(sizeof($dayTimes)-1)]);

	function getDaysInWeek ($weekNumber, $year, $dayStart = 1) {		  
	  // Count from '0104' because January 4th is always in week 1
	  // (according to ISO 8601).
	  $time = strtotime($year . '0104 +' . ($weekNumber - 1).' weeks');
	  // Get the time of the first day of the week
	  $dayTime = strtotime('-' . (date('w', $time) - $dayStart) . ' days', $time);
	  // Get the times of days 0 -> 6
	  $dayTimes = array ();
	  for ($i = 0; $i < 7; ++$i) {
		$dayTimes[] = strtotime('+' . $i . ' days', $dayTime);
	  }
	  // Return timestamps for mon-sun.
	  return $dayTimes;
	}
			  
			  
  $myCalendar = new tc_calendar("date3", true, false);
  $myCalendar->setIcon("images/iconCalendar.gif");
  $myCalendar->setDate(date('d', strtotime($date1)), date('m', strtotime($date1)), date('Y', strtotime($date1)));
  $myCalendar->setPath("./");
  $myCalendar->setYearInterval(1970, 2020);
  //$myCalendar->dateAllow('2009-02-20', "", false);
  $myCalendar->writeScript();	  
?>
      
      
<div style="float: left;">
                <div style="float: left; padding-left: 3px; padding-right: 3px; line-height: 18px;">to</div>
                <div style="float: left;">
<?php
  $myCalendar = new tc_calendar("date4", true, false);
  $myCalendar->setIcon("images/iconCalendar.gif");
  $myCalendar->setDate(date('d', strtotime($date2)), date('m', strtotime($date2)), date('Y', strtotime($date2)));
  $myCalendar->setPath("./");
  $myCalendar->setYearInterval(1970, 2020);
  //$myCalendar->dateAllow("", '2009-11-03', false);
  $myCalendar->writeScript();	  
?>
                </div>
              </div>      
                </div>
              </div>
              
            </li>
            <li>
              <label for="message">Message <span class="red">*</span></label>
              <textarea id="message" name="message" rows="6" cols="50"></textarea>
            </li>
            <li class="buttons">
              <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
              <div class="clr"></div>
            </li>
          </ol>
        </form>

 

And this is the PHP form processor.

 

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="<span class=\"error-red\">Invalid email address entered</span>";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','phone',$enquiries,'message');
$required = array('name','email','phone','enquiries','message');

$your_email = "[email protected]";
$email_subject = "Website Enquiries: ".$_POST['subject'];
$email_content = "New message:\n";

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'enquiries' && $key != 'email') {
	  if( empty($_POST[$value]) ) { echo '<span class="error-red">PLEASE FILL IN REQUIRED FIELDS!</span>'; exit; }
	}
	$email_content .= $value.': '.$_POST[$value]."\n";
  }
}

if(@mail($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}
}
?>

The form handling script, aside from being illogically structured, appears to rely on 'register_globals = On', and that's not a good thing.

 

I don't see anywhere in the script where the value of the date or enquiry form fields are used, so that is why you aren't getting the values in the resulting email.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.