The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> php send form not working
mircea dobre
post Dec 21 2015, 10:33 PM
Post #1





Group: Members
Posts: 1
Joined: 21-December 15
Member No.: 23,843



Hi guys,

I am working on a hotel web page with a reservation form. I have some issues as it doesn't send the setails. Here's is the form along with the reservation.php.
Cheers,

<!-- Reservation form -->
<section id="reservation-form">
<div class="container">
<div class="row">
<div class="col-md-12">
<form class="form-inline reservation-horizontal clearfix" role="form" method="post" action="php/reservation.php" name="reservationform" id="reservationform">
<div id="message"></div><!-- Error message display -->
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label for="email" accesskey="E">E-mail</label>
<input name="email" type="text" id="email" value="" class="form-control" placeholder="Ingrese su correo electrónico."/>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="room">Tipos de Habitación</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select class="form-control" name="room" id="room">
<option selected="selected" disabled="disabled">Tipos de Habitación</option>
<option value="Single">Simple</option>
<option value="Double">Doble</option>
<option value="Deluxe">Triple</option>
<option value="Matrimonial">Matrimonial</option>
</select>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="checkin">Día de Llegada</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Check-In is from 11:00"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<i class="fa fa-calendar infield"></i>
<input name="checkin" type="text" id="checkin" value="" class="form-control" placeholder="Check-in"/>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label for="checkout">Día de Salida</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="Check-out is from 12:00"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<i class="fa fa-calendar infield"></i>
<input name="checkout" type="text" id="checkout" value="" class="form-control" placeholder="Check-out"/>
</div>
</div>
<div class="col-sm-1">
<div class="form-group">
<div class="guests-select">
<label>Personas</label>
<i class="fa fa-user infield"></i>
<div class="total form-control" id="test">1</div>
<div class="guests">
<div class="form-group adults">
<label for="adults">Adultas</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="+18 años"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select name="adults" id="adults" class="form-control">
<option value="1">1 adulto</option>
<option value="2">2 adultos</option>
<option value="3">3 adultos</option>
<option value="4">4 adultos</option>
<option value="5">5 adultos</option>
<option value="6">6 adultos</option>
<option value="7">7 adultos</option>
<option value="8">8 adultos</option>
<option value="9">9 adultos</option>
</select>
</div>
<div class="form-group children">
<label for="children">Children</label>
<div class="popover-icon" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" data-content="0 hasta 18 años"> <i class="fa fa-info-circle fa-lg"> </i> </div>
<select name="children" id="children" class="form-control">
<option value="0">0 Niños</option>
<option value="1">1 niño</option>
<option value="2">2 niños</option>
<option value="3">3 niños</option>
</select>
</div>
<button type="button" class="btn btn-default button-save btn-block">Save</button>
</div>
</div>
</div>
</div>
<div class="col-sm-2">
<button type="submit" class="btn btn-primary btn-block">Book Now</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>






This is reservation.php

<?php

if(!$_POST) exit;

// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\. )+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|b
h|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|co
m|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|
fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|h
r|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|
ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|m
q|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu
|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc
|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|t
o|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|
zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");


$email = $_POST['email'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$room = $_POST['room'];
$adults = $_POST['adults'];
$children = $_POST['children'];


if(trim($email) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Attention! Please enter a valid email address.</div>';
exit();

} else if(trim($room) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Attention! Please enter a your room.</div>';
exit();

} else if(trim($checkin) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Attention! Please enter your check-in date.</div>';
exit();

} else if(trim($checkout) == '') {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Attention! Please enter your check-out date.</div>';
exit();

} else if(!isEmail($email)) {
echo '<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}

if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}


// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "myemail@gmail.com";

//$address = "myemail@yahoo.com";
$address = "myemail@gmail.com";


// Configuration option.
$e_subject = 'A reservation request by ' . $email . '.';


// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

$e_body = "Good news! A reservation has been requested by $email

The customer wants to check-in at: $checkin
and check-out at: $checkout

The customer requested a $room room for $adults adult(s) and $children child(ren)." . PHP_EOL . PHP_EOL;

$e_reply = "You can contact the customer via email, $email or hit 'reply' in your email browser to make the reservation complete.";

$msg = wordwrap( $e_body . $e_reply, 70 );

$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {

// Email has sent successfully, echo a success page.

echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Reservation sent successfully!</h1>";
echo "<p>Thank you, your reservation has been submitted to us and we'll contact you as quickly as possible to complete your booking.</p>";
echo "</div>";
echo "</fieldset>";

} else {

echo 'ERROR!';

}

This post has been edited by mircea dobre: Dec 21 2015, 10:34 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 22 2015, 09:35 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Your reservation.php page runs fine for me, as long as I insert the PHP closing tag at the end. But I must say it is a terrible design. Your validation tests are performed 1 at a time instead of all at once. If an error is found then you exit the script instead of reloading the form, with previous answers filled in. I would redesign the script logic
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
masonh928
post Jan 12 2016, 11:59 PM
Post #3


Serious Coder
*****

Group: Members
Posts: 253
Joined: 17-August 13
From: Indiana
Member No.: 19,570



Agree with Charles. Also may I ask if you have for example name attributes for inputs, but also you're going about this all wrong. The logic is not clear to me.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Sam A
post Feb 15 2016, 05:17 AM
Post #4


Novice
**

Group: Members
Posts: 26
Joined: 22-April 15
Member No.: 22,515



Your code is looking very conjugated. So i want more time to understand it and then after i will actually tell you what is the problem.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 01:27 PM