%attr>
title => 'Contact Form'
section => 'contact'
%attr>
<%once>
BEGIN{ push @INC, "/ionix/www/shared/modules","/home/vhosts/shared/modules"; }
use Email;
%once>
<%shared>
my $contact_email = 'info@beachcombermotel.com.au';
my $company = "Beachcomber Motel";
my %contact = ();
my @errors = ();
my %reasons = (
enquiry => "General Enquiry",
website => "Website"
);
%shared>
Contact Us
<%perl>
# Grab arguments and transfer to hash
$contact{name} = $ARGS{name};
$contact{phone} = $ARGS{phone};
$contact{email} = $ARGS{email};
$contact{reason} = $ARGS{reason};
$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, "Name: $contact{name}";
push @msg, "Phone: $contact{phone}";
push @msg, "Email: $contact{email}";
push @msg, "";
push @msg, "== Begin Comments ==";
push @msg, "";
push @msg, split "\n", $contact{comments};
push @msg, "";
push @msg, "== End Comments ==";
my $ret = Email->send_email(
$contact_email,
$contact{email},
"[Web Contact Form] - $reasons{$contact{reason}}",
$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');
}
%perl>
<%def .contact_form>
Please fill out the contact form to send us a query:
% if(scalar @errors > 0){
% my $err;
% foreach $err (@errors){
- <% $err %>
% }
%}
%def>
<%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 comments
if($contact{comments} eq ""){
push @errors, 'You have not entered any comments or queries.';
$valid = 0;
}
return $valid;
%perl>
%def>
<%def .contact_error>
Unfortunately we have not been able to process your comments due to an error occuring.
Please try again soon.
<% $company %>
%def>
<%def .contact_success>
Thank you for contacting us.
Your comments have been submitted and we will endeavour to respond as soon as possible.
<% $company %>
%def>