I tried earlier with no solution, so I'm adding all my code to try and resolve this issue. I am not getting this form in my inbox, but my ajax function is working like it should. I have godaddy hosting, and am running it locally on wampp for mac. I've tried multiple different email addresses with no avail. I don't want to use php mailer. I just want this to function properly instead of what it seems to be doing which is shooting emails into outter space
html
<div class="block">
<div class="done">
<h1>Thank you! I have received your message.</h1>
</div>
<div class="form">
<form method="post" action="scripts/process.php">
<input name="name" class="text" placeholder="Name" type="text" />
<input name="email" class="text" placeholder="Email" type="text" />
<textarea name="comment" class="text textarea" placeholder="Comment"></textarea>
<input name="submit" value="Let's Go!" id="submit" type="submit" />
<div class="loading"></div>
</form></div>
</div>
<div class="clear"></div>
</div>
</div>
jquery validation and ajax
$('#submit').click(function () {
//Get the data from all the fields
var name = $('input[name=name]');
var email = $('input[name=email]');
var comment = $('textarea[name=comment]');
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var emailVal = email.val();
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
if (!emailReg.test(emailVal)){
email.addClass('hightlight');
return false;
} else email.removeClass('hightlight');
if (name.val()=='') {
name.addClass('hightlight');
}else{name.removeClass('hightlight');}
if (email.val()=='') {
email.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (comment.val()=='') {
comment.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (name.val()=='' || email.val()=='' || comment.val()=='') {
return false;
}
//organize the data properly
var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
+ website.val() + '&comment=' + encodeURIComponent(comment.val());
//disabled all the text fields
$('.text').attr('disabled','true');
//show the loading sign
$('.loading').show();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "scripts/process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.form').fadeOut('slow');
//show the success message
$('.done').fadeIn('slow');
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, unexpected error. Please try again later.');
}
});
//cancel the submit button default behaviours
return false;
});
and the php which I regret to say I know very little about for now
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your comment.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = 'myemail#gmail.com';
//sender
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! Matt has received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
There are so many issues on sending PHP mails to different mail servers. For example, when I want to send email to GMail hosts I never include \r for new lines and I only go with \n. Maybe your problem is with your headers, I place my code here and see what you can get:
function send($address, $subject, $content, $from = '', $html = FALSE, $encoding = 'utf-8')
{
if(empty($address) || empty($content)) return;
$headers = "";
if($from != '')
{
$headers .= "From: {$from}\n";
$headers .= "Reply-To: {$from}\n";
}
$headers .= "To: {$address}\n";
if($html)
{
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset={$encoding}\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
}
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$headers .= "X-Mailer: PHP/" . phpversion();
set_time_limit(30);
mail($address, $subject, $content, $headers);
}
send('myemail#myhost.com', 'title', 'content', 'myemail <myemail#myhost.com>', FALSE);
Related
I have a simple contact form. It sends email via AJAX. Works fine.
Now I need to create PDF file from results of this form and download it to user like here
So html form:
<form id="contact-form">
<input type="hidden" name="action" value="contact_send" />
<input type="text" name="name" placeholder="Your name..." />
<input type="email" name="email" placeholder="Your email..." />
<textarea name="message" placeholder="Your message..."></textarea>
<input type="submit" value="Send Message" />
</form>
In functions.php I have function to send email:
function sendContactFormToSiteAdmin () {
try {
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
throw new Exception('Bad form parameters. Check the markup to make sure you are naming the inputs correctly.');
}
if (!is_email($_POST['email'])) {
throw new Exception('Email address not formatted correctly.');
}
$subject = 'Contact Form: '.$reason.' - '.$_POST['name'];
$headers = 'From: My Blog Contact Form <contact#myblog.com>';
$send_to = "contact#myblog.com";
$subject = "MyBlog Contact Form ($reason): ".$_POST['name'];
$message = "Message from ".$_POST['name'].": \n\n ". $_POST['message'] . " \n\n Reply to: " . $_POST['email'];
if (wp_mail($send_to, $subject, $message, $headers)) {
echo json_encode(array('status' => 'success', 'message' => 'Contact message sent.'));
exit;
} else {
throw new Exception('Failed to send email. Check AJAX handler.');
}
} catch (Exception $e) {
echo json_encode(array('status' => 'error', 'message' => $e->getMessage()));
exit;
}
}
add_action("wp_ajax_contact_send", "sendContactFormToSiteAdmin");
add_action("wp_ajax_nopriv_contact_send", "sendContactFormToSiteAdmin");
So in footer.php i have a script ajax handler:
jQuery(document).ready(function ($) {
$('#contact-form').submit(function (e) {
e.preventDefault(); // Prevent the default form submit
var $this = $(this); // Cache this
$.ajax({
url: '<?php echo admin_url("admin-ajax.php") ?>', // Let WordPress figure this url out...
type: 'post',
dataType: 'JSON', // Set this so we don't need to decode the response...
data: $this.serialize(), // One-liner form data prep...
beforeSend: function () {},
error: handleFormError,
success: function (data) {
if (data.status === 'success') {
handleFormSuccess();
} else {
handleFormError(); // If we don't get the expected response, it's an error...
}
}
});
});
});
All of it works great. But i don't understand where i have to paste code for creation PDF, i have tried to paste it in sendContactFormToSiteAdmin php function, but it didn't work.
As in this example i need to paste this code exactly in sendContactFormToSiteAdmin php function:
ob_start();
?>
<h1>Data from form</h1>
<p>Name: <?php echo $name;?></p>
<p>Email: <?php echo $email;?></p>
<?php
$body = ob_get_clean();
$body = iconv("UTF-8","UTF-8//IGNORE",$body);
include("mpdf/mpdf.php");
$mpdf=new \mPDF('c','A4','','' , 0, 0, 0, 0, 0, 0);
$mpdf->WriteHTML($body);
$mpdf->Output('demo.pdf','D');
But i don't understand how to do this with ajax response.
Edit
As Shoaib Zafar commented, if it is possible to email pdf file as an attachment to email, of course for me it is the best.
To email the PDF as an attachment, you need to alter your email sending function.
function sendContactFormToSiteAdmin () {
try {
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
throw new Exception('Bad form parameters. Check the markup to make sure you are naming the inputs correctly.');
}
if (!is_email($_POST['email'])) {
throw new Exception('Email address not formatted correctly.');
}
ob_start();
?>
<h1>Data from form</h1>
<p>Name: <?php echo $_POST['name'];?></p>
<p>Email: <?php echo $_POST['email'];?></p>
<?php
$body = ob_get_clean();
// Supposing you have already included ("mpdf/mpdf.php");
$mpdf=new \mPDF('c','A4','','' , 0, 0, 0, 0, 0, 0);
$mpdf->WriteHTML($body);
$pdf_content = $mpdf->Output('', 'S');
$pdf_content = chunk_split(base64_encode($pdf_content));
$uid = md5(uniqid(time()));
$filename = 'contact.pdf';
$subject = 'Contact Form: '.$reason.' - '.$_POST['name'];
$message = "Message from ".$_POST['name'].": \n\n ". $_POST['message'] . " \n\n Reply to: " . $_POST['email'];
$header = 'From: My Blog Contact Form <contact#myblog.com>';
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $pdf_content."\r\n\r\n";
$header .= "--".$uid."--";
$send_to = "contact#myblog.com";
$subject = "MyBlog Contact Form ($reason): ".$_POST['name'];
if (wp_mail($send_to, $subject, $message, $header)) {
echo json_encode(array('status' => 'success', 'message' => 'Contact message sent.'));
exit;
} else {
throw new Exception('Failed to send email. Check AJAX handler.');
}
} catch (Exception $e) {
echo json_encode(array('status' => 'error', 'message' => $e->getMessage()));
exit;
}
}
I don't know much about how wp_email function work but technically this code should work, you only need to refactor it.
And you can also find this in the official documentation to learn more about it mPDF Example #3
I have a simple POST script for PHP which sends an email, but when I click the submit button it executes and then goes to the script directory (ex: localhost/sendMail/test.php). Is it possible to post an alert box, and then stay on the page instead of going to the script and then redirecting back onto the submit page?
This is my script.
<?php
$subject = 'Your website: Contact'; // Subject of your email
$to = 'myemail'; // Enter recipient's E-mail address
$emailTo = $_REQUEST['email'];
$headers = "MIME-Version: 1.1";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: " . $emailTo . "\r\n"; // Sender's E-mail
$headers .= "Return-Path:". $emailTo;
$body = 'You have received a new inquiry!' . "\n\n";
$body .= 'Name: ' . $_REQUEST['name'] . "\n";
$body .= 'Email: ' . $_REQUEST['email'] . "\n";
$body .= 'Phone: ' . $_REQUEST['phone'] . "\n\n";
$body .= 'Message: ' . $_REQUEST['message'];
if($_REQUEST['name'] != "" && $_REQUEST['email'] != "" && $_REQUEST['phone'] != "" && $_REQUEST['message'] != "")
{
if (#mail($to, $subject, $body, $headers))
{
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sents';
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
}
else
{
$message = "Invalid fields!";
echo "<script type='text/javascript'>alert('$message');</script>";
//header("Location: http://localhost/abtek/contact.html");
exit;
}
?>
So when the alert is executed, is it possible to stop it from going to the script, and instead staying on the page until the fields are all valid to submit? As well as when they are submitted to display an alert again and stay on the page instead of doing a bunch of redirects.
Any help would be greatly appreciated.
You can submit the form with ajax/jquery and stop the redirect. See here: Stackoverflow
You can use jQuery, like this:
$('#my-submit').on('click', function(e){
e.preventDefault(); // prevents regular form submission
$.ajax({
url: 'localhost/sendMail/test.php',
data: $('form').serialize(),
success: function(result){
alert('Message: ' + result );
},
error: function(err){
alert(err)
}
})
});
In your PHP you should just do echo $message; to handle error better.
Read all you can about jQuery/AJAX, as there are important options you can explode, like using JSON.
I'm very new to PHP and am using a basic template 'send-mail' form on a contact page.
It's been requested that I send the email out to multiple email addresses when the "Submit" button is clicked. I've searched around & haven't quite found what I needed. What code do I need to add into the form below in order to send this out to multiple email addresses?
<?php
$mail_to = 'daniel30293#gmail.com'; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$web = $_POST['sender_web'];
$company = $_POST['sender_company'];
$addy = $_POST['sender_addy'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Web Prayer Request from ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Prayer Request: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');
window.location = 'prayer-request.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator admin#bondofperfection.com');
window.location = 'prayer-request.php';
</script>
<?php
}
?>
Your help is greatly appreciated.
You implode an array of recipients:
$recipients = array('jack#gmail.com', 'jill#gmail.com');
mail(implode(',', $recipients), $submit, $message, $headers);
See the PHP: Mail function reference - http://php.net/manual/en/function.mail.php
Receiver, or receivers of the mail.
The formatting of this string must comply with » RFC 2822. Some examples are:
user#example.com
user#example.com, anotheruser#example.com
User <user#example.com>
User <user#example.com>, Another User <anotheruser#example.com>
Just add multiple recipients comma seperated in your $mail_to variable like so:
$mail_to = 'nobody#example.com,anotheruser#example.com,yetanotheruser#example.com';
See
mail() function in PHP
Here is a simple example:
<?php
// Has the form been submitted?
// formSubmit: <input type="submit" name="formSubmit">
if (isset($_POST['formSubmit'])) {
// Set some variables
$required_fields = array('name', 'email');
$errors = array();
$success_message = "Congrats! Your message has been sent successfully!";
$sendmail_error_message = "Oops! Something has gone wrong, please try later.";
// Cool the form has been submitted! Let's loop through the required fields and check
// if they meet our condition(s)
foreach ($required_fields as $fieldName) {
// If the current field in the loop is NOT part of the form submission -OR-
// if the current field in the loop is empty, then...
if (!isset($_POST[$fieldName]) || empty($_POST[$fieldName])) {
// add a reference to the errors array, indicating that these conditions have failed
$errors[$fieldName] = "The {$fieldName} is required!";
}
}
// Proceed if there aren't any errors
if (empty($errors)) {
$name = htmlspecialchars(trim($_POST['name']), ENT_QUOTES, 'UTF-8' );
$email = htmlspecialchars(trim($_POST['email']), ENT_QUOTES, 'UTF-8' );
// Email Sender Settings
$to_emails = "anonymous1#example.com, anonymous2#example.com";
$subject = 'Web Prayer Request from ' . $name;
$message = "From: {$name}";
$message .= "Email: {$email}";
$headers = "From: {$name}\r\n";
$headers .= "Reply-To: {$email}\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if (mail($to_emails, $subject, $message, $headers)) {
echo $success_message;
} else {
echo $sendmail_error_message;
}
} else {
foreach($errors as $invalid_field_msg) {
echo "<p>{$invalid_field_msg}</p>";
}
}
}
Alright, I'm starting to pull my hair and I need some help :)
Here is my file which is used to select activated emails from users and send them some sort of newsletter.
Content of the newsletter.php
<?php
//Include configuration file
include 'config/config.php';
$pdo = new PDO("mysql:host=localhost;dbname=$db", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Define messages
//Error messages
define('ERROR_MESSAGE_SUBJECT', 'Enter subject');
define('ERROR_MESSAGE_CONTENT', 'Enter some content');
//Define variables
$errorFlag = false;
$to = array();
//Grab variables
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$newsletterSubject = check_input($_POST['newsletterSubject']);
$newsletterContent = $_POST['newsletterContent'];
if(!$newsletterSubject) {
$errorSubject = ERROR_MESSAGE_SUBJECT;
$errorFlag = true;
}
if(!$newsletterContent) {
$errorContent = ERROR_MESSAGE_CONTENT;
$errorFlag = true;
}
}
?>
<form action="newsletter.php" method="post">
<label>Naslov newsletter-a: <?php echo '<span class="error">'.$errorSubject.'</span>';?></label>
<input type="text" class="linput rounded" name="newsletterSubject">
<label>Sadržaj newsletter-a: <?php echo '<span class="error">'.$errorContent.'</span>';?></label>
<textarea name="newsletterContent" class="rounded"></textarea><br>
<input type="submit" class="submit button rounded" name="newsletterSend" value="Pošalji newsletter korisnicima">
</form>
<?php
if (!$errorFlag) {
echo '
<div class="heading">
<h1>Sending statistic</h1>
</div>';
$query = $pdo->prepare('SELECT email FROM users WHERE active=:active');
$query->bindValue(':active', '1');
$query->execute();
$query->setFetchMode(PDO::FETCH_ASSOC);
$i=1;
while($row = $query->fetch()) {
$to[] = $row['email'];
}
print_r($to);
if(!empty($to)) {
foreach($to as $mail) {
$headers = "From: " . $fromEmail . "\r\n";
$headers .= "Reply-To: ". $fromEmail . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= $newsletterContent;
$message .= '</body></html>';
mail($mail, $newsletterSubject, $message, $headers);
$i++;
}
}
}
?>
After selecting active emails from database, array $to contains:
Array ( [0] => somemail1#domain.com [1] => somemail2#domain.com )
And that is correct, but both emails will receive 2 emails, so 4 in total. Normally one email should receive one newsletter.
And there is also something else strange, when first newsletter is received, it contains subject and message. However second newsletter doesnt contain anything except 'to' field.
So to sum up, this file sends two emails per one email in database.
I tried to create test file with same array and this is content of it:
test.php
<?php
$fromEmail = 'from#mydomain.com';
$to = array('somemail1#domain.com', 'somemail2#domain.com');
print_r($to);
foreach($to as $mail) {
$headers = "From: " . $fromEmail . "\r\n";
$headers .= "Reply-To: ". $fromEmail . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= $newsletterContent;
$message .= '</body></html>';
mail($mail, $newsletterSubject, $message, $headers);
$i++;
}
?>
This test file sends normal email - one email per one email. So server configuration should be okay.
It looks like it's because your send code isn't inside the code block which checks that it is POST, so it sends once when you load the page and again when you fill in the form and submit it.
Move the whole if (!$errorFlag) block into the if ($_SERVER['REQUEST_METHOD'] == 'POST') block.
Might be easier to look at this fiddle: http://jsfiddle.net/pkAGz/ and the process.php code is shown below:
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter a name.';
//if the errors array is empty, send the mail
if (!$errors) {
$name = $name[array_rand($name)];
$to = '$name <$name email adress if set>';
//sender
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//echo "\n\n$name has been nominated to make the tea!\n\n";
//echo "\n\nThey will also be notified by e-mail if you entered their address.\n\n";
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo "\n\n$name has been nominated to make the tea!\n\nThey will also be notified by e-mail if you entered their address.\n\n";
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
Once the AJAX request is working the next step is simply work around the code to send an e-mail to the person chosen if their e-mail address was entered - a bit stuck on how to do that as I want the e-mail field to remain optional.
Then obviously, I want to return the name of the person that was picked at random and that will be it!
Thanks,
Martin
Use Firebug for Firefox, or watch the console in Chrome/Safari. So you would have seen that you have a javascript error:
Uncaught ReferenceError: comment is not defined
So the script:
//cancel the submit button default behaviours
return false;
isn't executed and the form is posted normally.