php datepicker form not submitting correctly

Hi,
I followed this tutorial here http://www.plus2net.com/php_tutorial/date-selection.php and it worked fine and I managed to add it to my form. It all posts ok until i decided that i needed two seperate dates. So I copied and pasted the table data with the form which has one submit button at the bottom of the tables. The problem is that only the second table (the second drop down box dates) actually submits to my email. The first set of dates don’t show up at all. (The name and email address all works ok). Anyone got any ideas. I’m a complete php newby…so go easy :slight_smile:

[php]<?php

if (isset($_POST[‘contact_name’]) && isset($_POST[‘contact_email’]) && isset ($_POST[‘contact_text’])) {
$contact_name = $_POST[‘contact_name’];
$contact_email = $_POST[‘contact_email’];
$contact_text = $_POST[‘contact_text’];

 $todo=$_POST['todo'];

if(isset($todo) and $todo==“submit”){

	$dt=$_POST['dt'];
	$month=$_POST['month'];
	$year=$_POST['year'];
	$date_value="$dt/$month/$year";

}

if (!empty ($contact_name) && !empty ($contact_email) && !empty ($contact_text)) {

if (strlen($contact_name)>30 || strlen($contact_email)>50 || strlen($contact_text)>1000) {
echo ‘Sorry maxlength for some field has been exceeded.’;
} else {

	$to = '[email protected]';
	$subject = 'Holiday dates form submitted.';
	$body = $contact_name. "\n". $contact_text. "\n". $date_value;
	$headers = 'From:' .$contact_email;

if (@mail($to, $subject, $body, $headers)) {

			echo 'Thanks for contacting us. We\'ll be in touch soon.';
}				else {
						echo 'Sorry, an error has occurred. Please try again later, or alternatively send us an email.';	
	
}	

}

} else	{
		echo 'All fields are required.';

}
}

?>[/php]

and the form code below:

[code]
Name:



Email address:



Message:



<input type="hidden" name="todo" value="submit">
Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
        <input type="submit" id="formbutton" value="Send">
[/code]

Thats it!!
Louise :slight_smile:

they have the same name month try month1 and month2 as the input name

Do it for the others names of the inputs as well day year.
The problem is that you set one value then set the second value, the second value will always show as it unsets the first value.

You are trying to put 2 values in to one place, you cant put 2 shoes on one foot.

Maybe you want to ask for your email to be taken out of that post to maybe one of the mods will do that for you if you ask them.

thanks for replying :slight_smile:
I’ll try what you said. btw how do i contact a moderator or here to have the email address taken out of the post?
Thanks

I added the input names and that didn’t seem to help :frowning:

How do I both of the calenders to just one value of ‘todo’ instead of trying to send the two values. Would it be possible to do that, if so then how could I do that?

Louise :slight_smile: :’(

You would have to add more tha one post vars to the script to get the second one

[php]

$dt=$_POST[‘dt1’];
$month=$_POST[‘month1’];
$year=$_POST[‘year1’];
$date_value="$dt1/$month1/$year1";

$dt=$_POST[‘dt2’];
$month=$_POST[‘month2’];
$year=$_POST[‘year2’];
$date_value="$dt2/$month2/$year2";

[/php]

You have to change the php as well as the form.

you have added 2 dates so you will need to add another set of _POST vars to eht php and make changes to the php to accept them and add them to the email.

[php]
$date_value
$date_value2
[/php]

[php]$body = $contact_name. “\n”. $contact_text. “\n”. $date_value;[/php]
[php]$body = $contact_name. “\n”. $contact_text. “\n”. $date_value. “\n”. $date_value2;[/php]

[php]<?php

if (isset($_POST[‘contact_name’]) && isset($_POST[‘contact_email’]) && isset ($_POST[‘contact_text’])) {
$contact_name = $_POST[‘contact_name’];
$contact_email = $_POST[‘contact_email’];
$contact_text = $_POST[‘contact_text’];

 $todo=$_POST['todo'];

if(isset($todo) and $todo==“submit”){

	$dt=$_POST['dt1'];
	$month=$_POST['month1'];
	$year=$_POST['year1'];
	$date_value1="$dt1/$month1/$year1";
		
		$dt=$_POST['dt2'];
		$month=$_POST['month2'];
		$year=$_POST['year2'];
		$date_value2="$dt2/$month2/$year2";

}

if (!empty ($contact_name) && !empty ($contact_email) && !empty ($contact_text)) {

if (strlen($contact_name)>30 || strlen($contact_email)>50 || strlen($contact_text)>1000) {
echo ‘Sorry maxlength for some field has been exceeded.’;
} else {

	$to = '';
	$subject = 'Holiday dates form submitted.';
	$body = $contact_name. "\n". $contact_text. "\n". $date_value1. "\n". $date_value2;
	$headers = 'From:' .$contact_email;

if (@mail($to, $subject, $body, $headers)) {

			echo 'Thanks for contacting us. We\'ll be in touch soon.';
}				else {
						echo 'Sorry, an error has occurred. Please try again later, or alternatively send us an email.';	
	
}	

}

} else	{
		echo 'All fields are required.';

}
}

?>[/php]

[code]

Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
        <input type="submit" id="formbutton" value="Send">
[/code]

I have pasted above the php and the form as it is now. (I’ve taken my email address out of this post too). I did what you recommended and it makes sense that it should work but when I received the email i got // // where the dates should be. It seems to be picking up the slashes separating the dates but not the dates themselves…odd…
Louise :’(

don’t know why its displayed the code like that. I used the php and # buttons…grrrrrrr :o

try the dates like this

[php]$date_value1=$dt1."/".$month1."/".$year1;[/php]
[php]$date_value2=$dt2."/".$month2."/".$year2;[/php]

I’ve just changed the dt2, month2, and $date_value2 into seconddt, secondmonth, and $date_valuetwo.
Now the second date shows up in my email but the first is still displayed as //.

You are still calling the same names for the year values
select name is also the same as select name = year they must be changed to yearone yeartwo also but leave the hidden input year1 and year2 each name value has to be different.

Once you go through the full script renaming each part of the code, so it has separate names for input and select then it should be good to go.

[php]
Select Year[/php]
[php]
Select Year[/php]

You can also echo out your post values so you can see them
[php]
echo $_POST[‘year1’];
echo $_POST[‘year2’];
echo $_POST[‘yeartwo’];

[/php]

This works as far as it posts the corerect values for the code, you will have to add in your other hidden inputs and code this is to show you how to set up the form properly so you get the correct values you want.

You need to use the php and code buttons on your code as well.

[php]

<?php if(isset($_POST['submit'])){ if (isset($_POST['contact_name']) && isset($_POST['contact_email']) && isset ($_POST['contact_text'])) { $contact_name = $_POST['contact_name']; $contact_email = $_POST['contact_email']; $contact_text = $_POST['contact_text']; $todo=$_POST['todo']; } if(isset($todo) and $todo=="submit"){ $dt1=$_POST['dt1']; $month1=$_POST['month1']; $year1=$_POST['year1']; $date_value1 = $dt1.'/'.$month1.'/'.$year1; $dt2=$_POST['dt2']; $month2=$_POST['month2']; $year2=$_POST['year2']; $date_value2 = $dt2.'/'.$month2.'/'.$year2; } if (!empty ($contact_name) && !empty ($contact_email) && !empty ($contact_text)) { if (strlen($contact_name)>30 || strlen($contact_email)>50 || strlen($contact_text)>1000) { echo 'Sorry maxlength for some field has been exceeded.'; } else { $to = ''; $subject = 'Holiday dates form submitted.'; $body = $contact_name. "\n". $contact_text. "\n". $date_value1. "\n". $date_value2; $headers = 'From:' .$contact_email; if (mail($to, $subject, $body, $headers)) { echo 'Thanks for contacting us. We\'ll be in touch soon.'; } else { echo 'Sorry, an error has occurred. Please try again later, or alternatively send us an email.'; } } } else { echo 'All fields are required.'; } } if(isset($contact_name)){ echo '
contact_name = '.$contact_name.'
'; } if(isset($contact_email)){ echo 'contact_email = '.$contact_email.'
'; } if(isset($contact_text)){ echo 'contact_text = '.$contact_text.'
'; } if(isset($todo)){ echo 'todo = '.$todo.'
'; } if(isset($date_value1)){ echo 'date 1 = '.$date_value1 .'
'; } if(isset($date_value2)){ echo 'date 2 = '.$date_value2.'
'; } ?> Name:


Email address:


Message:


Select Month Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
Select Month January February March April May June July August September October November December Date 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Select Year 2012 2013
[/php]

I’ve done what you said and it all works great :slight_smile: many thanks for your help ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service