Skip to content

Instantly share code, notes, and snippets.

@somatonic
Created April 5, 2012 21:39
Show Gist options
  • Save somatonic/2314407 to your computer and use it in GitHub Desktop.
Save somatonic/2314407 to your computer and use it in GitHub Desktop.
<?php
include($config->paths->root . "site/.libs/countries/countryList.class.php");
$ct = new CountryList();
$countries = $ct->getCountryList($lang);
$show_form = true;
$note = '<h3>Danke!</h3>';
$errors = '';
$success = false;
$valid = false;
$wert = fRequest::encode("wert");
$wert_custom = fRequest::encode("wert_custom");
$anrede = fRequest::encode("anrede");
$titel = fRequest::encode("titel");
$name = fRequest::encode("name");
$vorname = fRequest::encode("vorname");
$adresse = fRequest::encode("adresse");
$firma = fRequest::encode("firma");
$plz = fRequest::encode("plz");
$ort = fRequest::encode("ort");
$land = fRequest::encode("land");
$email = fRequest::encode("email");
$telefon = fRequest::encode("telefon");
$lieferadresse = fRequest::encode("lieferadresse");
$e_anrede = fRequest::encode("e_anrede");
$e_titel = fRequest::encode("e_titel");
$e_name = fRequest::encode("e_name");
$e_vorname = fRequest::encode("e_vorname");
$e_adresse = fRequest::encode("e_adresse");
$e_firma = fRequest::encode("e_firma");
$e_plz = fRequest::encode("e_plz");
$e_ort = fRequest::encode("e_ort");
$e_land = fRequest::encode("e_land");
$e_bemerkung = fRequest::encode("e_bemerkung");
function showError($err){
return "<br/><p class='error'>$err</p>";
}
function check_wert($value) {
$value = intVal($value);
if($value < 100 || $value > 1000) return false;
else return true;
}
if (fRequest::isPost()) {
try {
fRequest::validateCSRFToken(fRequest::get('request_token'));
try {
$validator = new fValidation();
$validator->addStringReplacement('Please enter a value', "Bitte ausfüllen");
$validator->addStringReplacement('Please enter an email address in the form [email protected]', "Bitte E-Mail Adresse eingeben im Format [email protected]");
$validator->addStringReplacement('Please enter a whole number', "Bitte eine Zahl eingeben");
$validator->addRequiredFields('wert','vorname','email','email','adresse','plz','ort','land','telefon');
$validator->addConditionalRule('wert', 'custom' , 'wert_custom');
$validator->addConditionalRule('lieferadresse', true , array('e_name', 'e_vorname', 'e_adresse','e_plz','e_ort','e_land'));
$validator->addCallbackRule('wert_custom','check_wert','Bitte mind. CHF 100.- und max. CHF 1000.-');
$validator->addEmailFields('email');
$errors = $validator->validate(true,true);
if ($errors) {
throw new fValidationException();
} else {
$show_form = false;
$mail = new fEmail();
$mail->addRecipient('...', '...');
$mail->setFromEmail('...', '...');
//$mail->addBCCRecipient('...');
$mail->setSubject('Online Gutschein Bestellung');
$date = date("d.m.Y - H:i:s");
$body = <<<_END
Bestellung Wertgutschein
$date
Anrede: $anrede
Titel: $titel
Name: $name
Vorname: $vorname
Firma: $firma
Adresse: $adresse
PLZ: $plz
Ort : $ort
Land : $land
E-Mail: $email
Telefon: $email
Lieferadresse:
Anrede: $e_anrede
Titel: $e_titel
Name: $e_name
Vorname: $e_vorname
Firma: $e_firma
Adresse: $e_adresse
PLZ: $e_plz
Ort : $e_ort
Land : $e_land
Bemerkung: $e_bemerkung
_END;
$mail->setBody(fHTML::decode($body) ,false);
$message_id = $mail->send();
}
} catch (fValidationException $e){
fMessaging::create('error',"<p class='error'>Fehler: Das Formular ist nicht korrekt ausgefüllt.</p>");
$show_form = true;
}
} catch (fExpectedException $e) {
//$e->printMessage();
fMessaging::create('warning',"user", "<p class='error'>Formular wurde aus Sicherheitsgründen gesperrt, probieren Sie es nochmals.</p>");
$show_form = true;
}
}
?>
<div class="inner indent">
<h1><?php echo $page->headline ?></h1>
<div class="title"><?php echo $page->title ?></div>
<?php echo $page->body; ?>
<?php
if($show_form) :
echo "<h2>Wertgutschein kaufen</h2>";
if (fMessaging::check("error")) {
$error = fMessaging::retrieve("error");
echo $error;
// echo "<p class='error'>";
// foreach($errors as $key => $message){
// echo "$message<br/>";
// }
// echo "</p>";
}
if (fMessaging::check("warning","user")) {
$warning = fMessaging::retrieve("warning","user");
echo $warning;
}
?>
<form action="#" class="common-form" method="post">
<input type="hidden" name="request_token" value="<?php echo fRequest::generateCSRFToken() ?>"/>
<fieldset>
<legend>Gutschein</legend>
<div class="row clearfix">
<label>Wert*</label>
<div style="float:left;width:75%" class="clearfix">
<label for="wert1" class="inline"><input <?php if($wert == '100') echo "checked='checked'" ?> type="radio" id="wert1" name="wert" value="100"/>Wert CHF 100.-</label><br/>
<label for="wert2" class="inline"><input <?php if($wert == '300') echo "checked='checked'" ?> type="radio" id="wert2" name="wert" value="300"/>Wert CHF 300.-</label><br/>
<label for="wert3" class="inline"><input <?php if($wert == 'custom') echo "checked='checked'" ?> type="radio" id="wert3" name="wert" value="custom"/>Wert </label>
<input type="text" style="float:left;width:60px" name="wert_custom" id="wert_custom" value="<?php echo $wert_custom ?>"/>&nbsp;CHF<br/>
</div>
<?php echo isset($errors['wert']) ? showError($errors['wert']) : '' ?>
<?php echo isset($errors['wert_custom']) ? showError($errors['wert_custom']) : '' ?>
</div>
</fieldset>
<fieldset>
<legend>Rechnungsadresse</legend>
<div class="row clearfix">
<label>Anrede</label>
<label for="frau" class="inline"><input <?php if($anrede == 'frau') echo "checked='checked'" ?> type="radio" id="frau" name="anrede" value="frau"/> Frau</label>
<label for="herr" class="inline"><input <?php if($anrede == 'herr') echo "checked='checked'" ?> type="radio" id="herr" name="anrede" value="herr"/> Herr</label>
<?php echo isset($errors['anrede']) ? showError($errors['anrede']) : '' ?>
</div>
<div class="row clearfix">
<label for="titel">Titel</label><input type="text" id="titel" name="titel" value="<?php echo $titel ?>"/>
<?php echo isset($errors['titel']) ? showError($errors['titel']) : '' ?>
</div>
<div class="row clearfix">
<label for="vorname">Vorname*</label><input type="text" id="vorname" name="vorname" value="<?php echo $vorname ?>"/>
<?php echo isset($errors['vorname']) ? showError($errors['vorname']) : ''?>
</div>
<div class="row clearfix">
<label for="name">Name*</label><input type="text" id="name" name="name" value="<?php echo $name ?>"/>
<?php echo isset($errors['name']) ? showError($errors['name']) : '' ?>
</div>
<div class="row clearfix">
<label for="firma">Firma</label><input type="text" id="firma" name="firma" value="<?php echo $firma ?>"/>
<?php echo isset($errors['firma']) ? showError($errors['firma']) : '' ?>
</div>
<div class="row clearfix">
<label for="adresse">Strasse/Nr.*</label><input type="text" id="adresse" name="adresse" value="<?php echo $adresse ?>"/>
<?php echo isset($errors['adresse']) ? showError($errors['adresse']) : '' ?>
</div>
<div class="row clearfix">
<label for="plz">PLZ*</label><input type="text" id="plz" name="plz" value="<?php echo $plz ?>"/>
<?php echo isset($errors['plz']) ? showError($errors['plz']) : '' ?>
</div>
<div class="row clearfix">
<label for="ort">Ort*</label><input type="text" id="ort" name="ort" value="<?php echo $ort ?>"/>
<?php echo isset($errors['ort']) ? showError($errors['ort']) : '' ?>
</div>
<div class="row clearfix">
<label for="land">Land*</label>
<select name="land" id="land">
<option value=''>Bitte wählen</option>
<?php
foreach($countries as $c => $n){
$opt = '';
if($land == $c) $opt = "selected='selected'";
echo "<option $opt value='$c'>$n</option>";
}
?>
</select>
</div>
<div class="row clearfix">
<label for="email">E-Mail*</label><input type="text" id="email" name="email" value="<?php echo $email ?>"/>
<?php echo isset($errors['email']) ? showError($errors['email']) : '' ?>
</div>
<div class="row clearfix">
<label for="telefon">Telefon*</label><input type="text" id="telefon" name="telefon" value="<?php echo $telefon ?>"/>
<?php echo isset($errors['telefon']) ? showError($errors['telefon']) : '' ?>
</div>
</fieldset>
<div class="row clearfix">
<label>&nbsp;</label>
<label for="lieferadresse" class="inline">
<input type="checkbox" id="lieferadresse" name="lieferadresse" <?php if($lieferadresse) echo "checked='checked'" ?>/>Andere Lieferadresse</label>
</div>
<fieldset id="lieferadresse_fieldset" style="display:<?php if($lieferadresse) echo "block"; else echo "none" ?>">
<legend>Lieferadresse</legend>
<div class="row clearfix">
<label>Anrede</label>
<label for="e_frau" class="inline"><input <?php if($e_anrede == 'e_frau') echo "checked='checked'" ?> type="radio" id="e_frau" name="e_anrede" value="e_frau"/> Frau</label>
<label for="e_herr" class="inline"><input <?php if($e_anrede == 'e_herr') echo "checked='checked'" ?> type="radio" id="e_herr" name="e_anrede" value="e_herr"/> Herr</label>
</div>
<div class="row clearfix">
<label for="e_titel">Titel</label><input type="text" id="e_titel" name="e_titel"/>
<?php echo isset($errors['e_titel']) ? showError($errors['e_titel']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_vorname">Vorname*</label><input type="text" id="e_vorname" name="e_vorname"/>
<?php echo isset($errors['e_vorname']) ? showError($errors['e_vorname']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_name">Name*</label><input type="text" id="e_name" name="e_name"/>
<?php echo isset($errors['e_name']) ? showError($errors['e_name']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_firma">Firma</label><input type="text" id="e_firma" name="e_firma"/>
<?php echo isset($errors['e_firma']) ? showError($errors['e_firma']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_adresse">Strasse/Nr.*</label><input type="text" id="e_adresse" name="e_adresse"/>
<?php echo isset($errors['e_adresse']) ? showError($errors['e_adresse']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_plz">PLZ*</label><input type="text" id="e_plz" name="e_plz"/>
<?php echo isset($errors['e_plz']) ? showError($errors['e_plz']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_ort">Ort*</label><input type="text" id="e_ort" name="e_ort"/>
<?php echo isset($errors['e_ort']) ? showError($errors['e_ort']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_land">Land*</label>
<select name="e_land" id="e_land">
<option value=''>Bitte wählen</option>
<?php
foreach($countries as $c => $n){
$opt = '';
if($e_land == $c) $opt = "selected='selected'";
echo "<option $opt value='$c'>$n</option>";
}
?>
</select>
<?php echo isset($errors['e_land']) ? showError($errors['e_land']) : '' ?>
</div>
<div class="row clearfix">
<label for="e_bemerkung">Bemerkungen</label><textarea type="text" rows="5" id="e_bemerkung" name="e_bemerkung"><?php echo $e_bemerkung ?></textarea>
</div>
</fieldset>
<p>* Pflichtfelder</p>
<div class="clearfix">
<input type="submit" name="submit" value="senden"/>
</div>
</form>
<script>
$('#lieferadresse').change(function(){
if($(this).is(":checked")) {
$('#lieferadresse_fieldset').slideDown();
} else{
$('#lieferadresse_fieldset').slideUp();
}
});
$('input[name="wert"]').change(function(){
if($(this).val != 'custom') {
$('#wert_custom').attr('value','');
}
});
</script>
<?php
else:
echo $note;
endif;
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment