Dufam ze pomoze:
Formular obsahuje polia:
-> meno
-> priezvisko
-> email
-> potvrd email
-> predmet
-> sprava
Chcelo by to odladit, doplnit hlavicku ku odosielaniu emailu, pripradne pouzit napr. phpmailer-a...
Ja pri inputoch pouzivam triedu inputData, takze si tie inputy mozes potom pomocou tohto nastylizovat, takisto inputButton, ako aj cely FIELDSET...
Myslim si ale, ze ako zaciatocny point by ti to mohlo pomoct...
Kód:
<?php
// def funkcii pouzitych v skripte
// validacia mena
function verify_name($name)
{
if (!eregi('^[[:alpha:]\.\' \-]{3,}$', $name)) return false;
else return true;
}
// email validacia
function valid_email($email)
{
if ((!ereg(".+\@.+\..+", $email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $email)))
return false;
else
return true;
}
// form submitted
if (isset($_POST['Submit']) && isset($_POST['act']) && ($_POST['act'] == "sendContactForm"))
{
// bezpecnostny bod
$firstName = @strip_tags(@trim($_POST['firstName']));
$surname = @strip_tags(@trim($_POST['surname']));
$email = @strip_tags(@trim($_POST['email']));
$confirmEmail = @strip_tags(@trim($_POST['confirmEmail']));
$subject = @strip_tags(@trim($_POST['predmet']));
$comments = @strip_tags(@trim($_POST['comments']));
// validacia
if (empty($firstName) || !verify_name($firstName) || empty($surname) || !verify_name($surname) || empty($email) || empty($confirmEmail) || (!valid_email($email)) || empty($comments) || empty($subject))
{
if (empty($firstName) || !verify_name($firstName)) $errorFirstName = true;
if (empty($surname) || !verify_name($surname)) $errorSurname = true;
if (empty($email) || (!valid_email($email))) $errorEmail = true;
if (empty($confirmEmail)) $errorConfirmEmail = true;
if (empty($comments)) $errorComments = true;
if (empty($subject)) $errorSubject = true;
$errorGeneral = true;
}
// kontroluej ci overil sopravne email v druhom poli
elseif ($email != $confirmEmail)
{
$errorConfirmEmailMatch = "Your 'Email' does not match the 'Confirm Email'.";
$errorGeneral = true;
}
else
{
// odosli email -> pouzijem kod od senton-a -> chcelo by to doplnit este hlavicku
// ale odporucal by som napr. phpmailer
$komu = "tvoj_email@abc.com";
$predmet = $subject;
$text = "";
$text .= "Od: ".$firstName. " ".$surname."\n";
$text .= "Odosielatelov email: ".$email."\n\n";
$text .= "Sprava:\n".$comments."\n";
if (mail($komu, $predmet, $text)) print "Sprava bola uspesne odoslana...";
else print "Sorry. Error pri odosielani. Prosim skus neskor.";
}
?>
<form action="http://<?php print $_SERVER['SERVER_NAME']; ?>/contact-us.php" method="post" class="contactForm">
<input type="hidden" name="act" value="sendContactForm" />
<fieldset>
<legend>Contact us by email</legend>
<!-- meno -->
<p>
<label for="firstName"<?php if ($errorFirstName) print " class=\"errorText\""; ?>>Meno *:</label>
<input type="text" name="firstName" id="firstName" value="<?php if (isset($_POST['act'])) print htmlentities($_POST['firstName'], ENT_QUOTES, 'UTF-8'); ?>" class="inputData" size="30" maxlength="30" />
</p>
<!-- priezvisko -->
<p>
<label for="surname"<?php if ($errorSurname) print " class=\"errorText\""; ?>>Priezvisko *:</label>
<input type="text" name="surname" id="surname" value="<?php if (isset($_POST['act'])) print htmlentities($_POST['surname'], ENT_QUOTES, 'UTF-8'); ?>" class="inputData" size="50" maxlength="50" />
</p>
<!-- email -->
<p>
<?php if (isset($errorConfirmEmailMatch)): ?>
<span class="errorText"><?php print $errorConfirmEmailMatch; ?></span><br />
<?php endif; ?>
<label for="email"<?php if ($errorEmail) print " class=\"errorText\""; ?>>Email *:</label>
<input type="text" name="email" id="email" value="<?php if (isset($_POST['act'])) print htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8'); ?>" class="inputData" size="50" maxlength="50" />
</p>
<!-- potvrd email -->
<p>
<label for="confirmEmail"<?php if ($errorConfirmEmail) print " class=\"errorText\""; ?>>Potvrd email *:</label>
<input type="text" name="confirmEmail" id="confirmEmail" value="<?php if (isset($_POST['act'])) print htmlentities($_POST['confirmEmail'], ENT_QUOTES, 'UTF-8'); ?>" class="inputData" size="50" maxlength="50" />
</p>
<!-- predmet -->
<p>
<label for="subject"<?php if ($errorSubject) print " class=\"errorText\""; ?>>Predmet *:</label>
<input type="text" name="subject" id="subject" value="<?php if (isset($_POST['act'])) print htmlentities($_POST['subject'], ENT_QUOTES, 'UTF-8'); ?>" class="inputData" size="50" maxlength="70" />
</p>
<!-- sprava -->
<p>
<label for="comments"<?php if ($errorComments == true) print " class=\"errorText\""; ?>>Sprava *:</label>
<textarea name="comments" id="comments" rows="7" cols="45" class="inputData"><?php if (isset($_POST['act'])) print htmlentities($_POST['comments'], ENT_QUOTES, 'UTF-8'); ?></textarea>
</p>
</fieldset>
<span class="smallText"><b>* required fields</b></span>
<!-- submit -->
<p class="submit">
<input type="submit" name="Submit" value="Send" class="inputButton" />
</p>
</form>
CEST