I would like to have a custom form with name, address and email fields. However, I am unsure how to achieve this using the proper magento way.
At the moment I have the following raw form in my cms page, which posts to a php file in the root of my magento:
<form action="/requestBrochure.php" id="brochureform" method="post">
<ul class="form-list">
<li><label>Name</label><br>
<input class="input-text required-entry" id="name" name="name" style="width: 250px;" type="text"></li>
<li><label>Email</label><br>
<input class="input-text required-entry" id="email" name="email" style="width: 250px;" type="text"></li>
<li><label>Address Line 1</label><br>
<input class="input-text required-entry" id="address_line_1" name="address_line_1" style="width: 250px;" type="text"></li>
<li><label>Address Line 2</label><br>
<input class="input-text required-entry" id="address_line_2" name="address_line_2" style="width: 250px;" type="text"></li>
<li><label>Address Line 3</label><br>
<input class="input-text" id="address_line_3" name="address_line_3" style="width: 250px;" type="text"></li>
<li><label>City</label><br>
<input class="input-text required-entry" id="city" name="city" style="width: 250px;" type="text"></li>
<li><label>Post Code</label><br>
<input class="input-text required-entry" id="postcode" name="postcode" style="width: 250px;" type="text"></li>
<li><label>Country</label><br>
<input class="input-text required-entry" id="country" name="country" style="width: 250px;" type="text"></li>
</ul><button class="form-button-alt" type="submit"><span>Submit Your Request</span></button>
</form>
The requestBrochure.php file:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$address_line_1 = $_POST["address_line_1"];
$address_line_2 = $_POST["address_line_2"];
$address_line_3 = $_POST["address_line_3"];
$postcode = $_POST["postcode"];
$city = $_POST["city"];
$country = $_POST["country"];
$to = "[email protected]";
$subject = "example Brochure Request";
$body .= "<p>The following customer have requested new example brochure.</p>";
$body .= "<p>Name : " . $name . "<p>";
$body .= "<p>Email : " . $email . "<p>";
$body .= "<p>Address Line 1 : " . $address_line_1 . "<p>";
$body .= "<p>Address Line 2 : " . $address_line_2 . "<p>";
$body .= "<p>Address Line 3 : " . $address_line_3 . "<p>";
$body .= "<p>City : " . $city . "<p>";
$body .= "<p>Post Code : " . $postcode . "<p>";
$body .= "<p>Country : " . $country . "<p>";
$body .= "<br /><p>Kind regards,</p><p>example Admin</p>";
$headers = "From: "."[email protected]"."\r\n" .
"Reply-To: "."[email protected]"."\r\n". "Content-Type: text/html; charset=ISO-8859-1\r\n" .
"X-Mailer: php";
$sent=mail($to, $subject, $body, $headers);
$to = $email;
$subject = "example Brochure Request";
$body = "<img src='/images/example_logo_email.jpg' >";
$body .= "
<p>Thank you for requesting our new catalogue, which will be posted out to you immediately.</p>
";
$headers = "From: "."[email protected]"."\r\n" .
"Reply-To: "."[email protected]"."\r\n". "Content-Type: text/html; charset=ISO-8859-1\r\n" .
"X-Mailer: php";
$sent=mail($to, $subject, $body, $headers);
if ($sent) {
} else {
}
header('Location: http://www.example.co.uk/thankyou' ) ;
This is a very simple way and is not the magento way. How can I do this in the correct manner?
I have also added the following external JS to my cms page:
var customForm = new varienForm('brochureform',true);
via:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<name>js/formvalid.js</name>
</action>
</reference>
But, no validation is occurring and the form is still posted. The external javascript is loaded.