سلام دوستان
من یه فرم فارسی با پی اچ پی نوشتم. ولی یه مشکلی وجود داره. وقتی که ارسال میکنم همه چی درهم میشه. از UTF-8 هم استفاده کردم و با Notepad ذخیره کردم. لطفا کمکم کنید. خیلی فوریه.
یه فرم کامله و میتونید در لوکال اجراش کنید.
من یه فرم فارسی با پی اچ پی نوشتم. ولی یه مشکلی وجود داره. وقتی که ارسال میکنم همه چی درهم میشه. از UTF-8 هم استفاده کردم و با Notepad ذخیره کردم. لطفا کمکم کنید. خیلی فوریه.
PHP:
<html dir="rtl">
<head>
<title></title>
<meta http-equiv=Content-Language content=en-us>
<meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<?php
// The main page logic:
// - If the form is submitted, validate and then process or redisplay
// - If it's not submitted, display
if ($_POST['_submit_check']) {
// If validate_form() returns errors, pass them to show_form()
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}
} else {
// The form wasn't submitted, so display
show_form();
}
function show_form($errors = '') {
// If the form is submitted, get defaults from submitted parameters
if ($_POST['_submit_check']) {
$defaults = $_POST;
} else {
// Otherwise, set our own defaults: medium size and yes to delivery
$defaults = array('first_name' => '',
'last_name' => '',
'email' => '',
'address' => '',
'city' => '',
'state' => '',
'country' => '');
}
// If errors were passed in, put them in $error_text (with HTML markup)
if ($errors) {
$error_text = '<th>لطفا موارد زیر را تصحیح کنید:';
$error_text .= '</th><tr><td><ul><li>';
$error_text .= implode('</li><li>',$errors);
$error_text .= '</li></ul></td></tr>';
} else {
// No errors? Then $error_text is blank
$error_text = '';
}
// Jump out of PHP mode to make displaying all the HTML tags easier
?>
<?php print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" >'; ?>
<table class="forms">
<?php print $error_text ?>
<tr><td>نام</td>
<td><?php print '<input type="text" name="first_name" size=20 value="' . htmlentities($defaults['first_name']). '">'; ?></td></tr>
<tr><td>نام خانوادگی</td>
<td><?php print '<input type="text" name="last_name" size=20 value="' . htmlentities($defaults['last_name']). '">'; ?>
</td></tr>
<tr><td>پست الکترونیک</td>
<td><?php print '<input type="text" name="email" size=20 value="' . htmlentities($defaults['email']). '">'; ?>
</td></tr>
<tr><td>نشانی</td>
<td>
<?php print '<input type="text" name="address" size=30 value="' . htmlentities($defaults['address']). '">'; ?>
</td></tr>
<tr><td>شهر</td>
<td>
<?php print '<input type="text" name="city" size=15 value="' . htmlentities($defaults['city']). '">'; ?>
</td></tr>
<tr><td>استان</td>
<td>
<?php print '<input type="text" name="state" size=15 value="' . htmlentities($defaults['state']). '">'; ?>
</td></tr>
<tr><td>کشور</td>
<td>
<?php print '<input type="text" name="country" size=15 value="' . htmlentities($defaults['country']). '">'; ?>
</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="ارسال" />
</td></tr>
</table>
<input type="hidden" name="_submit_check" value="1" />
</form>
<?php
} // The end of show_form()
function validate_form() {
$errors = array();
if (! strlen(trim($_POST['first_name']))) {
$errors[] = 'نام خود را وارد کنید';
} elseif (strlen(trim($_POST['first_name'])) < 3) {
$errors[] = 'نام خود را بطور کامل وارد کنید';
}
if (! strlen(trim($_POST['last_name']))) {
$errors[] = 'نام خوانوادگی خود را وارد کنید';
} elseif (strlen(trim($_POST['last_name'])) < 3) {
$errors[] = 'نام خانوادگی خود را بطور کامل وارد کنید';
}
if (! strlen(trim($_POST['email']))) {
$errors[] = 'نشانی پست الکترونیکی خود را وارد کنید';
} elseif (strlen(trim($_POST['email'])) < 3) {
$errors[] = 'نشانی پست الکترونیکی خود را بطور کامل وارد کنید';
} elseif (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i',
$_POST['email'])) {
$errors[] = 'نشانی پست الکترونیکی خود را بطور کامل وارد کنید';
}
return $errors;
}
function process_form() {
// build up the text of the order message
$thanks=<<<_ORDER_
$_POST[first_name]گرامی،
از حسن انتخاب شما متشکریم.
_ORDER_;
$message = "Name: $_POST[first_name] $_POST[last_name]\n";
$message .= "Email: $_POST[email]\n";
$message .= "FullAddress: $_POST[country], $_POST[state], $_POST[city], $_POST[address]\n";
// send the message to the sales team
mail('$salesmail', 'New Order', $message);
// print the message, but encode any HTML entities
// and turn newlines into <br/> tags
print nl2br(htmlentities($thanks));
}
?>
</body>
</html>