Formular PHP

Formular PHP

Tutorial formular php


De multe ori avem nevoie sa facem un formular php, pentru o pagina de contact, cariera, etc.

Acest formular php de contact ajuta clientii sa ne scrie rapid, fara sa mai intre in cont de mail, traim in secolul vitezei, iar timpul inseamna totul pentru noi… chiar daca unii nu isi dau seama.:)

In acest tutorial va prezint un formular php care include si captcha.

avem 3 fisiere: formular.php, trimis, php, si verificare-imagine.php.

Ele se pot modifica cum doriti, doar ca trebuie sa fie link intre ele.

formular.php

<!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>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>Untitled Document</title>

</head>

<body><table width=”600″ border=”0″ cellpadding=”0″ cellspacing=”0″>

<tr>

<td align=”left” valign=”top”><p>&nbsp;</p>

<form name=”form1″ action=”trimis.php” align=”center” method=”post” id=”form1″ style=”margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;”>

<table border=”0″ cellspacing=”0″ cellpadding=”0″>

<tr>

<td width=”138″ align=”left” valign=”middle” bgcolor=”#f2f2f2″>Nume*:</td>

<td width=”362″ align=”left” valign=”middle” bgcolor=”#f2f2f2″><input name=”nume” type=”text” id=”nume” style=”padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;” maxlength=”30″/></td>

</tr>

<tr>

<td align=”left” valign=”middle”>Telefon:</td>

<td align=”left” valign=”middle”><input name=”tel” type=”text” id=”tel” style=”padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;” maxlength=”50″/></td>

</tr>

<tr>

<td align=”left” valign=”middle”>E-mail:</td>

<td align=”left” valign=”middle”><input name=”from” type=”text” id=”from” style=”padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;” maxlength=”50″/></td>

</tr>

<tr>

<td align=”left” valign=”middle” bgcolor=”#f2f2f2″>Mesaj:</td>

<td align=”left” valign=”middle” bgcolor=”#f2f2f2″><textarea name=”message” rows=”3″ id=”message” style=”padding:2px; border:1px solid #CCCCCC; width:180px; height:40px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;”></textarea></td>

</tr>

<tr>

<td align=”left” valign=”middle”>Cod verificare (anti spam):</td>

<td align=”left” valign=”middle”><input name=”verif_box” type=”text” id=”verif_box” style=”padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;”/>

<img src=”verificare-imagine.php?<?php echo rand(0,9999);?>” alt=”scrieti din imagine” width=”50″ height=”24″ align=”absbottom” /></td>

</tr>

<tr>

<td align=”left” valign=”middle”>&nbsp;</td>

<td align=”left” valign=”middle”><!– if the variable “wrong_code” is sent from previous page then display the error field –>

<?php if(isset($_GET['wrong_code'])){?>

</p>

<div style=”border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;”>Codul de verificare este gresit !</div><?php ;}?></td>

</tr>

<tr>

<td align=”left” valign=”middle”>&nbsp;</td>

<td align=”left” valign=”middle”>&nbsp;</td>

</tr>

<tr>

<td align=”left” valign=”top”>

<input type=”reset” name=”Reset” id=”button” value=”Reset” style=”margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;”/>    </td>

<td align=”left” valign=”top”><input name=”Submit” type=”button” ONCLICK=”javascript:validateForm()”

value=”Trimite” style=”margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;”>       </td>

</tr>

</table>

</form>

</table>

</body>

</html>

trimis.php

<?php

// —————————————–

// nu uita sa schimbi office@msdesign.ro cu email-ul unde se va duce datele din formularul de contact.

// Incarca variabilele

$message = $_REQUEST["message"];

$from = $_REQUEST["from"];

$nume = $_REQUEST["nume"];

$tel = $_REQUEST["tel"];

$verif_box = $_REQUEST["verif_box"];

//

$message = stripslashes($message);

$from = stripslashes($from);

$nume = stripslashes($nume);

$tel = stripslashes($tel);

// verifica sa vada daca codul de verificare a fost introdus corect

if(md5($verif_box).’a4xn’ == $_COOKIE['tntcon']){

// Daca codul de verificare a fost corect mesajul este trimis si arata pagina

mail(“office@msdesign.ro”, ‘Mesaj din formular php’, $_SERVER['REMOTE_ADDR'].”\n\n”.”Nume: $nume”.”\n\n”.”Telefon: $tel”.”\n\n”.$message, “From: $from”);

//

setcookie(‘tntcon’,”);

} else {

// Daca codul de verificare nu este corect afiseaza

header(“Location:”.$_SERVER['HTTP_REFERER'].”?subject=$subject&from=$from&message=$message&wrong_code=true”);

exit;

}

?>

verificare-imagine.php

<?php

// —————————————–

//  The Web Help .com

// —————————————–

header(‘Content-type: image/jpeg’);

$width = 50;

$height = 24;

$my_image = imagecreatetruecolor($width, $height);

imagefill($my_image, 0, 0, 0xFFFFFF);

// add noise

for ($c = 0; $c < 40; $c++){

$x = rand(0,$width-1);

$y = rand(0,$height-1);

imagesetpixel($my_image, $x, $y, 0×000000);

}

$x = rand(1,10);

$y = rand(1,10);

$rand_string = rand(1000,9999);

imagestring($my_image, 5, $x, $y, $rand_string, 0×000000);

setcookie(‘tntcon’,(md5($rand_string).’a4xn’));

imagejpeg($my_image);

imagedestroy($my_image);

?>

Formular php testat si functional.

Pentru intrebari va stau la dispozitie.

Nu sunt articole similare.



5 Raspunsuri to “Formular PHP”

  1. djhmusic says:

    nu stiu ce naiba are dar la mine nu merge, l-am copiat in dreamweave cs 4 si nu merge dupa ce le-am salvat:(

  2. okazii says:

    intereant articol, mi-a fost de mare ajutor. tine-o tot asa.

  3. Only want to say your article is as tonishing. The clearness in your post is simply spectacular and i can take for granted you are an expert on this field. Well with your permission allow me to grab your rss feed to keep up to date with succeeding post. Thanks a million and please keep up the ac complished work.

  4. Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!!

Lasa raspuns