Posted: 10.08.2009 09:16 Post subject: contact form + upload
Zanima me jel tko od vas trebao ovaku kontakt forumu dakle standardna polja + upload fajla koji se tako?er ?alje na e-mail...tra?io sam malo po netu za gotove ali nisam ni?ta konkretno na?ao....pa ako tko ima kakvi link bio bi mu zahvalan
________
Suzuki GSX-R Series history
Last edited by n0p on 02.02.2011 12:40; edited 1 time in total
Joined: 25 Aug 2003 Posts: 1842 Location: Zagreb, Hrvatska
Posted: 11.08.2009 15:26 Post subject:
Nije komplicirano, trebas samo ispravno headere posloziti. Evo ti source fiktivnog formulara
slozenog nabrzaka, s podrskom za neograniceni broj attachmenta i ostalo:
// the "fixed" part of the message, if there is any...
$mail_msg = "\nPozdrav,\n\nSljede?a poruka je poslana koriste?i formu na Va?im stranicama.\n";
$mail_msg .= "Datoteke poslane preko forme bi se trebale nalaziti u privitku.\n\n";
if(trim($name) == '')
{
$error = '<div class="errormsg">Please enter your name!</div>';
}
else if(trim($email_from) == '')
{
$error = '<div class="errormsg">Please enter your email address!</div>';
}
else if(!isEmail($email_from))
{
$error = '<div class="errormsg">You have enter an invalid e-mail address. Please, try again!</div>';
}
if(trim($subject) == '')
{
$error = '<div class="errormsg">Please enter a subject!</div>';
}
else if(trim($mail_msg) == '')
{
$error = '<div class="errormsg">Please enter your message!</div>';
}
else if(trim($spamcheck) == '')
{
$error = '<div class="errormsg">Please enter the number for Spam Check!</div>';
}
else if(trim($spamcheck) != '5')
{
$error = '<div class="errormsg">Spam Check: The number you entered is not correct! 2 + 3 = ???</div>';
}
if($error == '')
{
if(get_magic_quotes_gpc())
{
$mail_msg = stripslashes($mail_msg);
}
// the email subject
// '[Contact Form] :' will appear automatically in the subject.
// You can change it as you want
$email_subject = '[Contact Form] : ' . $subject;
$filecount = 0;
$data = null;
if (isset($_FILES) && !empty($_FILES)) {
// this should work for any number of uploaded files, each will be attached separately
foreach ($_FILES as $file => $value) {
$attachment[(int)$filecount] = $_FILES[$file]['tmp_name'];
$attachment_name[(int)$filecount] = $_FILES[$file]['name'];
if (is_uploaded_file($attachment[(int)$filecount])) {
if ($_FILES[$file]['size'] <= $upload_filesize_limit) {
// does the file comply with our allowed mime types?
if (in_array($_FILES[$file]['type'], $valid_mime_types)) {
$fp = fopen($attachment[(int)$filecount], "rb");
$data[(int)$filecount] = fread($fp, filesize($attachment[(int)$filecount]));
// chunk it up and base64 encode so it can be emailed
$data[(int)$filecount] = chunk_split(base64_encode($data[(int)$filecount]));
fclose($fp);
$filecount++;
}
}
}
}
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|b
h|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu
|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|
gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|k
i|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms
|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|
pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|
sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|
vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-
9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
<!-- END CONTACT FORM -->
<p> </p>
<p style="text-align:center;">Go to the <a href="http://web-kreation.com/index.php/freebies/" title="Download the Contact form">Freebies</a> page to download this contact form.</p>
Joined: 25 Aug 2003 Posts: 1842 Location: Zagreb, Hrvatska
Posted: 04.09.2009 16:23 Post subject:
Klasika.
<form> elementu nedostaje enctype="multipart/form-data" atribut.
Bez toga form uploads ne funkcioniraju.
Code:
<form ... enctype="multipart/form-data">
EDIT: btw, editirao sam ti post gore da se site ne razlece zbog onog ogromnog regular
expressiona (koji je btw totalno nepotreban, ima puno laksih/boljih regexa za validaciju
email adrese).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum