<%attr> title => 'Booking Request' section => 'bookings' <%once> BEGIN{ push @INC, "/ionix/www/shared/modules","/home/vhosts/shared/modules"; } use Email; use DateTime; <%shared> my $contact_email = 'info@beachcombermotel.com.au'; my %contact = (); my @errors = (); my $company = "Beachcomber Motel";

Request a Booking

<%perl> # Grab arguments and transfer to hash $contact{name} = $ARGS{name}; $contact{phone} = $ARGS{phone}; $contact{email} = $ARGS{email}; $contact{address} = $ARGS{address}; $contact{city} = $ARGS{city}; $contact{state} = $ARGS{state}; $contact{postcode} = $ARGS{postcode}; $contact{date} = $ARGS{date}; $contact{nights} = $ARGS{nights}; $contact{area} = $ARGS{area}; $contact{comments} = $ARGS{comments}; if(exists $ARGS{send}){ # Validate contact form details if($m->comp('.contact_validate') == 1){ # Send email my @msg = (); push @msg, "Host IP: $ENV{REMOTE_ADDR}"; push @msg, ""; push @msg, "== Booking Request =="; push @msg, ""; push @msg, "Name: $contact{name}"; push @msg, "Phone: $contact{phone}"; push @msg, "Email: $contact{email}"; push @msg, ""; push @msg, "Address: $contact{address}"; push @msg, "City: $contact{city}"; push @msg, "State: $contact{state}"; push @msg, "Postcode: $contact{postcode}"; push @msg, ""; push @msg, "Date: $contact{date}"; push @msg, "No of Nights: $contact{nights}"; push @msg, "Type: $contact{type}"; push @msg, ""; push @msg, split "\n", $contact{comments}; push @msg, ""; push @msg, "== End =="; my $ret = Email->send_email( $contact_email, $contact{email}, "[Booking Request] - $contact{name}", $contact{name}, @msg ); if($ret == 1){ # Success $m->comp('.contact_success'); }else{ # Failed to send email! $m->comp('.contact_error'); } }else{ # Provide errors and contact form again $m->comp('.contact_form'); } }else{ # Display contact form $m->comp('.contact_form'); } <%def .contact_form>

In order to request a booking, please fill out the following form:

% if(scalar @errors > 0){

% my $err; % foreach $err (@errors){ - <% $err %>
% }

%}
Name :
Phone :
Email Address :
  
Address :
City :
State :
Postcode :
  
Date : (DD/MM/YYYY)
No of Nights:
Accommodation Type:
  
Comments :
 
<%def .contact_validate> <%perl> my $valid = 1; my $phonevalid = 1; my $emailvalid = 1; # Check name if(not ($contact{name} =~ /\w+/)){ push @errors, "You have not entered your name."; $valid = 0; } # Check phone number if(not ($contact{phone} =~ /\d+/)){ $phonevalid = 0; } # Check email address if(not ($contact{email} =~ /^[\w\.\-_]+\@[\w\-]+(\.[\w\-]+)*\.\w{2,3}(\.)?$/)){ $emailvalid = 0; } # Check that email address OR phone number has been provided if(not $emailvalid and not $phonevalid){ push @errors, "Please enter a valid email address and/or phone number."; $valid = 0; } # Check address if($contact{address} eq ''){ push @errors, "Please enter a valid address."; $valid = 0; } # Check city if($contact{city} eq ''){ push @errors, "Please enter a valid city."; $valid = 0; } # Check state if($contact{state} eq ''){ push @errors, "Please enter a valid state."; $valid = 0; } # Check postcode if($contact{postcode} eq ''){ push @errors, "Please enter a valid postcode."; $valid = 0; } # Check date if(DateTime->check_date_str($contact{date}) eq ''){ push @errors, "Please enter a valid date."; $valid = 0; } # Check number of nights if(not ($contact{nights} =~ /^\d+$/)){ push @errors, "Please enter a valid number of nights."; $valid = 0; } # Check area if(not ($contact{area} eq 'motel' || $contact{area} eq 'apartment')){ push @errors, "Please select an area to book."; $valid = 0; } # Check comments #if($contact{comments} eq ""){ # push @errors, 'You have not entered any comments or queries.'; # $valid = 0; #} return $valid; <%def .contact_error>

Unfortunately we have not been able to process your booking due to an error occuring.

Please try again soon.

<% $company %>

<%def .contact_success>

Thank you for requesting a booking.

We will be in contact with you shortly to confirm availability and complete your booking.

<% $company %>