Of course Vekia
Here it is:
if (isset($_POST['quickcontact'])){
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
if ( $_POST['subject'] != '' ) {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
} else if ($name =='' || $email =='' || $message ==''){
$this->errors[] = Tools::displayError('Please fill all required fields');
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$this->errors[] = Tools::displayError('Invalid email format');
} else{
$formcontent="From: $name \n Email: $email \n Message: $message";
$recipient = Configuration::get('PS_SHOP_EMAIL');
$subject = "Quick Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
header( 'Location: http://www.google.com' ) ;
}
}
But I have another problem with this. When I submit form it is displaying errors, but emptying all values from fileds. Maybe my solution isn't good And there is no way to put php into cms page via admin
UPDATE:
And I found solution for that also using jquery. If anyone is interested here is the solution.
if (isset($_POST['quickcontact'])){
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
echo '<script>';
print "var name = '$name'; var message = '$message'; var email = '$message';";
echo '</script>';
if ( $_POST['subject'] != '' ) {
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
} else if ($name =='' || $email =='' || $message ==''){
$this->errors[] = Tools::displayError('Please fill all required fields');
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$this->errors[] = Tools::displayError('Invalid email format');
} else{
$formcontent="From: $name \n Email: $email \n Message: $message";
$recipient = Configuration::get('PS_SHOP_EMAIL');
$subject = "Quick Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
header( 'Location: http://www.google.com' ) ;
}
}
And in CMS page inserted the jquery code
<script type="text/javascript">
// <![CDATA[
$(document).ready(function (){
$('input[name=name]').val(name);
$('textarea[name=message]').val(message);
$('input[name=email]').val(email);
});
// ]]>
</script>
Please Vekia tell me if this is OK way to do it