Hi all, I'm trying to use the jQuery datepicker to create a booking date selection thingy on a personal plugin I'm trying to develop.

This is the code I'm using to take an "arrival" date and a "departure" date, after click on the submit button the user is redirected to another page where he can compile the main form:

book_test.php

$(document).ready(function() {
        var dates = $( '#arrival, #departure' ).datepicker({
            defaultDate: '+1w',
            changeMonth: true,
            numberOfMonths: 1,
            onSelect: function( selectedDate ) {
                var option = this.id == 'arrival' ? 'minDate' : 'maxDate',
                    instance = $( this ).data( 'datepicker' ),
                    date = $.datepicker.parseDate(
                        instance.settings.dateFormat ||
                        $.datepicker._defaults.dateFormat,
                        selectedDate, instance.settings );
                dates.not( this ).datepicker( 'option', option, date );
            }        
        });
    });
...............
...............
...............
...............
<form name="grab" method="post" action="?page_id=52">
 Arrival<br />
 <input type="text" id="arrival" name="arrival">
 Departure<br />
 <input type="text" id="departure" name="departure"/>
 <input type="submit" value="Send" alt="Send request">
</form>

Here the user can fill the main form with name and so on:

form_main.php

<input type="text" name="arrival" disabled="yes" value="<?php echo $_POST['arrival']; ?>">
<input type="text" name="departure" disabled="yes" value="<?php echo $_POST['departure']; ?>">
<input type="text" name="name">
...............
...............
...............
...............
<input type="submit" id="button" name="button" value="Send" />

I'm trying to send this form to email, but I receive all the fields except the dates selected by the user, this is a part of the code I wrote:

mail.php

$name = $_REQUEST["name"];
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$verif_box = $_REQUEST["verif_box"];

$name = stripslashes($name); 
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$from = stripslashes($from); 

$body .= "Arrival Date: " . trim(date("d/m/Y", $_POST["arrival"])) . "\n";
$body .= "Departure: " . trim(date("d/m/Y", $_POST["departure"])) . "\n";
$body .= "Name: " . trim(stripslashes($_POST["name"])) . "\n";

But it prints these dates:
Arrival Date: 01/01/1970
Departure Date: 01/01/1970

Any hint?
At the moment the 1st little form sends the 2 variables (arrival and departure) to the second one (the main form) correctly, but I can't figure out why when I click on the Submit button of the main form I can't receive the correct dates in the mail.

Hope someone could help!

Cheers

Recommended Answers

All 5 Replies

Member Avatar for diafol
$( "#arrival" ).datepicker({ dateFormat: 'dd/mm/yy' });

will make the date in your format. If you don't want to do this, you'll have to change the input date via php:

date("d/m/Y",strtotime($_POST['arrival']));

Thank you for the answer, I've already tried the last line of code you wrote

date("d/m/Y",strtotime($_POST['arrival']));

unfortunately it prints: 01/01/1970

I tried to debug also the variable with print_r but it seems that the email form not receive the arrival and departure date at all

Fixed by myself, the problem was here:

disabled="yes"

Removed it and everything works great now

Thank you :D

Member Avatar for diafol

OK, mark as solved (link below) to prevent others wasting their time. :)

Did thank you. I wasted two days of tests :sad:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.