Скрипт бронирования для отеля

Hotel Reservation Form with PHP

Posted on November 10, 2021 by David Adams

In this article, we’ll be creating an elegant hotel reservation form with PHP, which will enable guests to submit reservations using an HTML form.

The code will consist of an HTML form and PHP to send the reservation form submissions to a specific email address. In addition, we’ll add validation to the form to prevent invalid data.

What is a hotel reservation form used for?

Well, it is self-explanatory. The form will enable guests to submit reservations on your website. The easy-to-use interface will provide an innovative experience for your guests. Fast and straightforward. Whether you own a hotel, motel, resort, or another type of accommodation. The form is ideal for your business.


1. Getting Started

Before we start coding our hotel reservation form, we need to ensure we have a working web server and meet all the requirements below. We cannot execute PHP code without a working web server as it is a server-side programming language.

1.1. Requirements

  • Web Server — If you haven’t installed a local web server solution package, I recommend you download and install XAMPP. XAMPP is an open-source web server solution package.
  • Mail Server (SMTP) — Without a working mail server, you’ll unable to receive emails that are processed using the reservation form. If you’re hosting your website with a provider, you shouldn’t need to do anything. However, if you have your own server (dedicated/vps), I recommend you install Postfix.

1.2. What You Will Learn in this Tutorial

  • Design a Hotel Reservation Form — We’ll be using CSS to design our hotel reservation form and HTML to structure our code.
  • Design a Email Template — Design a template suitable for emails using HTML and CSS.
  • Form Validation — Implement validation to individual elements in our form.
  • Send Mail — The PHP mail function will enable us to send mail to a specified email address.

1.3. Setup & File Structure

Now that we’ve installed a web server, we need to start it. In addition, we will create the directories and files we’re going to use for our hotel reservation form page.

  • Open the XAMPP Control Panel
  • Next to the Apache module, click Start
  • Next to the MySQL module, click Start
  • Navigate to XAMPPs installation directory (C:\xampp)
  • Open the htdocs directory
  • Create the following directories and files:

File Structure

\— hotelreservationform
|— hotel.php
|— email-template.php
|— style.css

The above files will contain the following:

  • hotel.php — This file will contain our hotel reservation form template and PHP code that will process the form.
  • email-template.php — This file will contain the email template code.
  • style.css — The stylesheet that will structure our page and make it look more appealing.

2. Designing the Hotel Reservation Form with CSS

The stylesheet will structure our layout and describe how each element will display on the screen. It includes the fonts, colors, and size of the elements.

Edit the style.css file and add:

That’s all we need to do for the stylesheet file. We can now move on to creating the reservation form template.

3. Structuring the Hotel Reservation Form with HTML

The reservation form will enable the guest to enter their details and submit them. We’ll create an HTML form element and append input elements that we’re going to use. In addition, we will specify attributes that will validate the elements.

Edit the hotel.php file and add:

That will create the base structure for our reservation form. As you can see, the style.css file is included in the head section along with the Font Awesome library, which will allow us to output icons in our form.

We have set the form’s method to post as the data we’re going to send needs to be enclosed in the body. The method is essential; without it, we cannot retrieve the form data with PHP.

There is no need to specify the action attribute as the code that will process the form will be in the same file, and therefore it’s not necessary. The empty value will submit the form to the current URL.

The above code will create the arrival and departure input elements, with both types declared as a date. The required attribute will ensure both input elements have been entered by the guest. They cannot submit the form without entering the date.

With PHP, we can retrieve the input element by the name attribute, so for instance, we can retrieve the arrival date with $_POST[‘arrival’], but only when the form has been submitted.

HTML TipWhen clicking the text inside a label element, it will toggle the associated input element, which is determined by the ID attribute.

The label elements will appear above the input field, and the containers surrounding the input elements will structure the layout.

The above code will add the first and last name elements, with both type attributes set as text. The placeholder text will appear in the background when the element is empty.

The above code will add the email field with the element’s type attribute set to email.

The above code will add the phone number element with the type attribute set to tel, which is the abbreviation for telephone number.

The above form elements are different to the ones we have previously created. Instead of the input elements, we are using drop-down elements that we can populate with numbers. Both the adults and children elements will be a drop-down list.

To add more items to the drop-down element, all you need to do is append an option element. For instance:

Similar to the element we implemented previously, both are using the select (drop-down) element. With the room preference element, the guest can specify the type of accommodation they want to stay in.

Finally, we can include the code that will submit the form.

If we navigate to the file in our web browser, we should see the following:

That’s all we need to do for the reservation form template. We can now proceed to create the email template.

4. Creating the Email Template

All reservation submissions will be sent to a specified email address using the email template. We will use output buffering to capture the file and bind it to the mail() function, which we will do in the next section.

Edit the email-template.php file and add:

The variables specified in the email template file will be declared in our hotel.php file.

When a guest makes a reservation, we will receive an email that will look similar to:

That’s all we need to do for the email template. In the next section, we will implement code that will process the reservation form.

5. Processing the Hotel Reservation Form with PHP

Finally, we need to include the code that will process the form data, which will consist of validation and sending the email using the email template we previously created.

Edit the hotel.php file and place the following code at the very top:

With the above code, we have declared the responses array that we will use to output validation and success messages. To check whether the form was submitted, we can use the isset() function as that will check if the variables are declared.

The above code will assign all the post variables that we are going to use and convert special characters to HTML entities.

PHP TipThe htmlspecialchars() function converts special characters to HTML entities and therefore preventing XSS attacks.

The above code will add basic validation to the email, first name and last name fields. You’re free to implement your own validation for the other fields.

Finally, the above code will send the email to the specified address using the captured template. Don’t forget to update the $to and $from variables.

That’s all we need to do for the hotel.php file. If you encounter a mail server error, you will need to verify that you have a working SMTP mail server and configure it accordingly. Without a working mail server, you will not receive emails.


Congratulations! You’ve successfully created your very own hotel reservation form with HTML, CSS and PHP! What next? Consider implementing validation for the other fields and connect the form to a MySQL database.

Consider sharing the article using the social links below if you’ve found it helpful and drop a comment below. We greatly appreciate the support.

Enjoy coding and thank you for reading!

About Author

David Adams

Enthusiastic website developer, I’ve been designing and developing web applications for over 10 years, I enjoy the creativity I put into my projects and enjoy what others bring to the awesome web. My goal is to help newcomers learn the ways of the web.


prowebber.cc — Тут есть все для настоящих вебмастеров

PROWEBBER » Web » Скрипты » Panda Multi Resorts v7.5.1 — скрипт бронирования для нескольких отелей

Panda Multi Resorts v7.5.1 — скрипт бронирования для нескольких отелей

Panda Multi Resorts — веб-программное обеспечение для создания и управления сайтами для нескольких отелей, курортов, спа. ВЫ: туристическое агентство, туроператор, сеть отелей или просто владелец нескольких отелей, санаториев или спа салон? Эта CMS создана для вас! Добавьте ваши отели и комнаты. Управляйте своими ценами. Создавайте оригинальные мероприятия и туры, дополнительные услуги и следите за вашими заказами!

Pandao Multi Resorts использует Pandao CMS, систему управления контентом, которая содержит простую, эргономичную и полную административную панель, которая позволяет легко управлять контентом вашего сайта в сочетании с легко настраиваемым шаблоном.
Несколько новых специальных модулей: бронирование, отели, номера, цены, валюты, дополнительные услуги и удобства.
Идеально подходит для веб-агентства, желающего быстро и просто распространять сайты для своих клиентов!
Pandao CMS полностью адаптивна, поэтому используйте ее как на смартфоне, так и на компьютере.

Основано на PDO / MySQL — PHP4 / 5 — HTML5 — CSS3 — Bootstrap 3.x

Missing update?
Checkout our NULLED Web Community

Дополнительные ссылки на скачивание ТОЛЬКО для зарегистрированных


Оцените статью