View Full Version : کمک درباره ایجاد فرم تماس با ما
mohsen78
چهارشنبه 22 مرداد 1393, 13:50 عصر
درود به دوستان گرامی ،من کمکی از دوستان میخواستم ، من یک سایت با HTML5 طراحی کردم حالا میخواستم یک فرم ارتباط با ما درست کنم ، مثل یک شخص که مشخصاتشو وارد کنه و سپس بتونه اطلاعاتش ذخیره و ارسال بشه... ممنون میشم کمکم کنید...خیلی هم عجله دارم
Mori Bone
چهارشنبه 22 مرداد 1393, 14:55 عصر
مشکل شما توی چیه طراحیش با html یا کد نویسیش با php؟
vimax23
چهارشنبه 22 مرداد 1393, 15:10 عصر
درود به دوستان گرامی ،من کمکی از دوستان میخواستم ، من یک سایت با HTML5 طراحی کردم حالا میخواستم یک فرم ارتباط با ما درست کنم ، مثل یک شخص که مشخصاتشو وارد کنه و سپس بتونه اطلاعاتش ذخیره و ارسال بشه... ممنون میشم کمکم کنید...خیلی هم عجله دارم
اطلاعات فقط ارسال بشه یا نه اطلاعات بره تو یه دیتابیسی و همزمان ارسال بشه
سینا اکبری
چهارشنبه 22 مرداد 1393, 19:14 عصر
کد زیر رو توی جایی که میخوای فرم نمایش داده بشه قرار بده.
و اگر خواستی دکمه ها ،اسم هاو...عوض کن و یا حذف.
آدرس سایتت رو هم عوض کن
<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> ( <a href="http://www.freecontactform.com/html_form.php">HTML Form</a> )
</td>
</tr>
</table>
</form>
بعدش کد زیر رو تو فایلی به نامhtml_form_send.php کپی کن و اگر خواستی متن انگلیسی که میگه با موفیقت ارسال شد و....از این چیزا رو هرچی میخوای بنویس و فایل رو توی هاست یا
سرورت آپلود کن
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "you@yourdomain.com";
$email_subject = "website html form submissions";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
ab.ali
چهارشنبه 22 مرداد 1393, 19:47 عصر
دوست عزیز با توجه به این که ایشون تازه وارد هستند به نظرم اگر ایشون خودشون یک کد php سبک بنویسن بهت از اینه که فقط از کد های آماده استفاده کنند.
سینا اکبری
چهارشنبه 22 مرداد 1393, 20:17 عصر
هر چه شما صلاح میدونید:افسرده:
mohsen78
پنج شنبه 23 مرداد 1393, 08:08 صبح
درود و تشکر از تمام دوستان، من فقط یک فرم ساده تماس با ما با HTML میخواستم با php آشنایی خیلی خیلی کمی دارم(البته دارم بطور جدی پیگیری میکنم تا php یاد بگیرم و مزاحم دوستان هم میشم) دو روز دیگه هم مهلت پروژم هستش.
mohsen78
پنج شنبه 23 مرداد 1393, 08:11 صبح
کد زیر رو توی جایی که میخوای فرم نمایش داده بشه قرار بده.
و اگر خواستی دکمه ها ،اسم هاو...عوض کن و یا حذف.
آدرس سایتت رو هم عوض کن
<form name="htmlform" method="post" action="html_form_send.php">
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> ( <a href="http://www.freecontactform.com/html_form.php">HTML Form</a> )
</td>
</tr>
</table>
</form>
با Html این کدشو دیدم حالا اطلاعات وارد شده توی فرم کجا و چجوری ذخیره میشه....؟
سینا اکبری
پنج شنبه 23 مرداد 1393, 09:01 صبح
توی دیتابیس .
به آدرس زیر برو کامل آموزش داده.
http://www.lynda.com/articles/send-email-from-a-web-form-with-php
vimax23
پنج شنبه 23 مرداد 1393, 10:37 صبح
درود و تشکر از تمام دوستان، من فقط یک فرم ساده تماس با ما با HTML میخواستم با php آشنایی خیلی خیلی کمی دارم(البته دارم بطور جدی پیگیری میکنم تا php یاد بگیرم و مزاحم دوستان هم میشم) دو روز دیگه هم مهلت پروژم هستش.
اول یه فرم میسازی مثلا یه تکست فیلد میزاری اینو میبری تو دیتابیس به این شکل
<form action="Contact.php" method="post">
اسم تو:<input type="text" id="Name" name="Name" />
<input type="submit" id="submit" value="بفرست" />
</form>
حالا مثلا تیبل به اسم Contacts با 3 تا رکورد مثلا آی دی و محتویات فیلد اسم تو و زمانی که ارسال شده رو میسازیم اینطوری
Create Table Contacts (
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100),
Created DATETIME
);
بعد یه فایل php واسه ریختن اطلاعات تو دیتابیس بسازی اینطوری {اسم این فایل رو همونطور که تو فرم مشخصه بده Contact.php}
<?php
$Name = $_POST["Name"];
$db = mysql_connect("localhost", "userdb", "passdb");
mysql_select_db("dbname", $db);
$sql = "INSERT INTO contacts (
Name,
Created
)
VALUES (
'$Name',
NOW()
)";
mysql_query($sql, $db);
mysql_close($db);
?>
حالا واسه اینکه سلکت کنی از دیتابیس یه فایلی مثل این میسازی میبینیش محتویات اون سه تا رو اینجا
<?php
$db = mysql_connect("localhost", "userdb", "passdb");
mysql_select_db("dbname", $db);
$result = mysql_query("SELECT * FROM contacts");
while ($row = mysql_fetch_array($result)) {
echo "<span style='padding-right:10px;'>".$row["ID"]."</span><span style='padding-right:10px;'>".$row["Name"]."</span>".$row["Created"]."<br />";
}
mysql_close($db);
?>
پ.ن:userdb / passdb / dbname به ترتیب اسم دیتابیست و یوزر پسوردشه
پ.ن2:این کد خیلی ساده هست واسه اینکه فیلد بیشتر بسازی ، حذف و اضافه کنی و.... کلی کار دیگه بهتره شی گرایی بنویسیش
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.