Here is my HTML :
<form method="post" action="<?php echo get_template_directory_uri(); ?>/mailer.php">
<div class="formRow alignCenter">
<input type="text" class="w25" name="name" data-validation="length" data-validation-length="min1" placeholder="نام و نام خانوادگی" />
<input type="text" class="w25" name="email" data-validation="email" placeholder="ایمیل" />
<input type="text" class="w30" name="phone" data-validation="number" placeholder="شماره تماس" />
<div class="clear"></div>
</div>
<div class="formRow">
<span class="green"><i class="fa fa-cog"></i> هسته سایت:</span>
<div class="horSpacer"></div>
<input type="radio" name="website_core" value="CMS" checked><label for="website_core"><abbr title="CMS ها اسکریپت هایی از پیش نوشته شده و آماده استفاده می باشند. استفاده از آنها باعث تسریع و کاهش هزینه در پروژه می شود.">CMS</abbr></label>
<div class="horSpacer small"></div>
<input type="radio" name="website_core" value="پرتال اختصاصی"><label for="website_core">پرتال اختصاصی</label>
</div>
<div class="formRow">
<span class="green"><i class="fa fa-wrench"></i> نوع وب سایت:</span>
<div class="horSpacer"></div>
<input type="radio" name="website_type" value="وب سایت شخصی" checked><label for="website_core">وب سایت شخصی</label>
<div class="horSpacer small"></div>
<input type="radio" name="website_type" value="وب سایت شرکتی"><label for="website_core">وب سایت شرکتی</label>
<div class="horSpacer small"></div>
<input type="radio" name="website_type" value="پرتال سازمانی"><label for="website_core">پرتال سازمانی</label>
<div class="horSpacer small"></div>
<input type="radio" name="website_type" value="فروشگاه اینترنتی"><label for="website_core">فروشگاه اینترنتی</label>
<div class="horSpacer small"></div>
<input type="radio" name="website_type" value="سایر"><label for="website_core">سایر</label>
<div class="horSpacer small"></div>
</div>
<div class="formRow">
<span class="green"><i class="fa fa-wrench"></i> خدمات:</span>
<div class="horSpacer"></div>
<input type="checkbox" name="website_services[]" value="راه اندازی کامل" id="wholeWebsite" checked><label for="website_core">راه اندازی کامل وب سایت</label>
<div class="horSpacer small"></div>
<input type="checkbox" name="website_services[]" value="طراحی PSD" id="wholeWebsite2" checked><label for="website_core">طراحی گرافیک و PSD</label>
<div class="horSpacer small"></div>
<input type="checkbox" name="website_services[]" value="تبدیل PSD به HTML" id="wholeWebsite3" checked><label for="website_core">تبدیل PSD به HTML</label>
<div class="horSpacer small"></div>
<input type="checkbox" name="website_services[]" value="پیاده سازی روی اسکریپت" id="wholeWebsite4" checked><label for="website_core">پیاده سازی روی اسکریپت</label>
</div>
<div class="formRow">
<span class="green"><i class="fa fa-wrench"></i> خدمات ویژه: </span>
<div class="horSpacer"></div>
<input type="checkbox" value="سئو" name="website_VIPservices"><label for="website_core"><abbr title="جایگاه بهتر سایت شما در نتایج جست و جوی گوگل">سئو و بهینه سازی / SEO</abbr></label>
<div class="horSpacer small"></div>
<input type="checkbox" value="ریسپانسیو" name="website_VIPservices"><label for="website_core"><abbr title="سازگاری کامل وب سایت شما با موبایل و تبلت ،علاوه بر کامپیوتر">ریسپانسیو / Responsive</abbr></label>
<div class="horSpacer small"></div>
<input type="checkbox" value="مدیریت" name="website_VIPservices"><label for="website_core"><abbr title="مدیریت وبسایت شما توسط ما انجام میشود.">ورود اطلاعات / Data Entry</abbr></label>
<div class="horSpacer small"></div>
<input type="checkbox" value="چند زبانه" name="website_VIPservices"><label for="website_core">چند زبانه</label>
<div class="horSpacer small"></div>
<input type="checkbox" value="تحویل فوری" name="website_VIPservices"><label for="website_core">تحویل فوری</label>
</div>
<div class="formRow">
<div class="colBig">
<div class="formRow">
<span class="blue"><i class="fa fa-wrench"></i> آدرس وب سایت مشابه آنچه مد نظر شماست را وارد کنید: </span>
<div class="horSpacer"></div>
<input type="text" class="w459 ltr" data-validation-optional="true" name="similarWebsite" value="http://www." />
<div class="clear"></div>
</div>
<div class="formRow">
<span class="orange"><i class="fa fa-wrench"></i> حدود بودجه در نظر گرفته شده برای پروژه: </span>
<div class="horSpacer"></div>
<input type="text" id="budjet" value="800000" name="budjet" data-slider="true" data-slider-theme="volume" data-slider-range="400000,5000000" data-slider-step="100000" data-slider-snap="true">
<div class="clear"></div>
</div>
</div>
<div class="colCustom1">
<div class="formRow" style="border-bottom:none;">
<span class="green"><i class="fa fa-wrench"></i> توضیحات لازم:</span>
<div class="horSpacer"></div>
<textarea class="w45" rows="5" name="desc" cols="132"></textarea>
<div class="clear"></div>
<div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="formRow" style="border-bottom:none;">
<p class="button"><input type="submit" value="ثبت سفارش" id="submit2" /></p>
<div class="loading"></div>
</div>
</form>
<div class="done">
<b>Thank you !</b> We have received your message.
</div>
</div>
And here is my jquery code :
<script>
$(document).ready(function() {
//if submit button is clicked
$('#submit2').click(function () {
//Get the data from all the fields
var name = $('input[name=name]');
var email = $('input[name=email]');
var phone = $('input[name=phone]');
var webcore = $('input[name=website_core]');
var webtype = $('input[name=website_type]');
var webservice = $("input[name='website_services[]']:checked");
var vipservices = $('input[name=website_VIPservices]');
var similar = $('input[name=similarWebsite]');
var budjet = $('input[name=budjet]');
var desc = $('textarea[name=desc]');
if (name.val()=='') {
name.addClass('error');
return false;
} else name.removeClass('error');
if (email.val()=='') {
email.addClass('error');
return false;
} else email.removeClass('error');
if (phone.val()=='') {
phone.addClass('error');
return false;
} else phone.removeClass('error');
if (desc.val()=='') {
desc.addClass('error');
return false;
} else desc.removeClass('error');
//organize the data properly
var data = 'name=' + name.val() + '&email=' + email.val() + '&phone='
+ phone.val() + '&webcore=' + webcore.val() + '&webtype=' + webtype.val() + '&webservice=' + webservice.val() + '&vipservices=' + vipservices.val() + '&similar=' + similar.val() + '&budjet=' + budjet.val() + '&desc=' + encodeURIComponent(desc.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: "<?php echo get_template_directory_uri(); ?>/mailer.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if mailer.php returned 1/true (send mail success)
if (html==1) {
//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;
});
});
</script>
and this is my PHP :
<?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'];
$phone = ($_GET['phone']) ?$_GET['phone'] : $_POST['phone'];
$webcore = ($_GET['website_core']) ?$_GET['website_core'] : $_POST['website_core'];
$webtype = ($_GET['webtype']) ?$_GET['webtype'] : $_POST['webtype'];
$webservice = ($_GET['webservice']) ?$_GET['webservice'] : $_POST['webservice'];
$vipservices = ($_GET['vipservices']) ?$_GET['vipservices'] : $_POST['vipservices'];
$similar = ($_GET['similar']) ?$_GET['similar'] : $_POST['similar'];
$budjet = ($_GET['budjet']) ?$_GET['budjet'] : $_POST['budjet'];
$desc = ($_GET['desc']) ?$_GET['desc'] : $_POST['desc'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$phone) $errors[count($errors)] = 'Please enter your comment.';
if (!$desc) $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 = 'saaaa@gmail.com';
//sender
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'ارسال سفارش از ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">
<head></head>
<body>
<table>
<tr><td>نام</td><td>' . $name . '</td></tr>
<tr><td>ایمیل</td><td>' . $email . '</td></tr>
<tr><td>تلفن</td><td>' . $phone . '</td></tr>
<tr><td>هسته سایت</td><td>' . $webcore . '</td></tr>
<tr><td>نوع سایت</td><td>' . $webtype . '</td></tr>
<tr><td>خدمات</td><td>' . $webservice . '</td></tr>
<tr><td>خدمات ویژه</td><td>' . $vipservices . '</td></tr>
<tr><td>سایت مشابه</td><td>' . $similar . '</td></tr>
<tr><td>بودجه</td><td>' . $budjet . '</td></tr>
<tr><td>توضیحات</td><td>' . nl2br($desc) . '</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! We have 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 '<a href="form.php">Back</a>';
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;
}
?>
Everything works fine , but if you check multiple checkboxes , the form will just send on of those. Not an array. (for example about input named website_services)
In other words , i will recieve this in my email "Website Services : b" instead of "Website Services : a,b,c,d"
Thanks
Aucun commentaire:
Enregistrer un commentaire