Hi Leute,
habe mir ein Kontaktformular als Vorlage "geschrieben". Könnt ihr es bitte auf seine "Perfektion" prüfen? Mir sagen was man besser machen könnte?
Danke im vorraus
drPhip132
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
index.php
PHP
<span class="syntaxhtml"><br /><span class="syntaxdefault"><?php<br /></span><span class="syntaxkeyword">if(</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'button'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxcomment">#wurde der submit button gedrückt?<br />#wenn ja läuft die auswertung weiter<br />#sonst bricht es ab<br /></span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#pflichtfelder<br /></span><span class="syntaxdefault"> $anrede </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'anrede'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $nachname </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'nachname'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $vorname </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'vorname'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $strasse </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'strasse'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $plz </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'plz'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $email </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'email'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $nachricht </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'nachricht'</span><span class="syntaxkeyword">];<br /><br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#freiwillige felder<br /></span><span class="syntaxdefault"> $firma </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'firma'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault"> $telefon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'telefon'</span><span class="syntaxkeyword">];<br /><br /><br /></span><span class="syntaxdefault"> if</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $_POST</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'button'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> if</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $anrede </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $nachname </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $vorname </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $strasse </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $plz </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $email </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> AND $nachricht </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#wenn alle pflichtfelder ausgefüllt sind...<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> $empfaenger </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"empfänger_email"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#deine emailadresse hier oben<br /></span><span class="syntaxdefault"> $absender </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $email</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> $betreff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Kontakt - "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $anrede </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $nachname </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">", "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $vorname</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> $mailtext </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Nachricht: "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $nachricht</span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">" | "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Firma: "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $firma </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">" | "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Telefon: "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> $telefon</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> $antwortan </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"empfänger_email"</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#deine email<br /><br /></span><span class="syntaxdefault"> mail</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $empfaenger</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> $betreff</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> $mailtext</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxstring">"From: $absender\nReply-To: $antwortan"</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> else<br /> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> $fehler </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> TRUE</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#irgendwo im quellcode fragen ob $fehler FALSE ist<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#dann an der gewünschten stelle ausgeben "bitte alle pflichtfelder ausfüllen"<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#oder so ähnlich<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br />}<br /></span><span class="syntaxdefault">?><br /></span><!DOCTYPE html><br /><html><br /><head><br /> <title>Titel</title><br /> <meta charset="UTF-8" /><br /><br /> <link href="style.css" type="text/css" rel="stylesheet" /><br /></head><br /><br /><body><br /><br /> <form method="post" action=""><br /> <label>* Anrede:<br /> <select name="anrede" ><br /> <option value="Herr">Herr </option><br /> <option value="Frau">Frau </option><br /> </select><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* Nachname:<br /> <input type="text" name="nachname" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* Vorname:<br /> <input type="text" name="vorname" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>Firma:<br /> <input type="text" name="firma" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* Straße / Nr:<br /> <input type="text" name="strasse" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* PLZ / Ort:<br /> <input type="text" name="plz" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>Telefon:<br /> <input type="tel" name="telefon" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* E-Mail:<br /> <input type="email" name="email" /><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <label>* Nachricht:<br /> <textarea name="nachricht" rows="13" cols="40"></textarea><br /> </label><br /><br /> <!-- ---------------------------------------------- --><br /><br /> <input type="submit" name="button" value="Absenden"/><br /><br /> </form><br /><br /></body><br /></html><br /></span>
design.css
Code
body
{
margin: 0;
padding: 0;
}
form
{
width: 500px;
padding: 20px;
}
fieldset
{
width: 100%;
}
label
{
width: 500px;
float: left;
margin: 6px 0;
}
input, select, textarea
{
width: 300px;
max-width: 300px;
/*wegen textarea max-width*/
max-height: 200px;
float: right;
}
input[type="submit"]
{
display: block;
float: none;
clear: both;
width: 120px;
margin: 0 auto;
}
Alles anzeigen