Last active
December 16, 2015 03:49
-
-
Save putzflorian/5372406 to your computer and use it in GitHub Desktop.
Formularversand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" action="send.php" onsubmit="this.action='';" enctype="application/x-www-form-urlencoded"> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mandatoryFields = array( | |
'firstname' => $this->_getParam('firstname'), | |
'lastname' => $this->_getParam('lastname'), | |
'street' => $this->_getParam('street'), | |
'zip' => $this->_getParam('zip'), | |
'city' => $this->_getParam('city'), | |
'land' => $this->_getParam('land'), | |
'email' => $this->_getParam('email') | |
); | |
$mandatory = Website_Tool_Formular::isMandatoryOK($mandatoryFields); | |
$this->view->mandatory = $mandatory; | |
if ($this->_getParam('submit') && !is_array($mandatory)) { | |
// send mail | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Website_Tool_Formular | |
{ | |
public static function isMandatoryOK($inputNames = array()) | |
{ | |
if ($inputNames == '' || !is_array($inputNames)) { | |
return false; | |
} | |
foreach ( | |
$inputNames as $key => $value | |
) { | |
if (is_array($value)) { | |
foreach ( | |
$value as $k => $v | |
) { | |
switch ($v) { | |
case 'FILTER_VALIDATE_BOOLEAN': | |
if (!filter_var($k, FILTER_VALIDATE_BOOLEAN)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_EMAIL': | |
if (!filter_var($k, FILTER_VALIDATE_EMAIL)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_FLOAT': | |
if (!filter_var($k, FILTER_VALIDATE_FLOAT)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_INT': | |
if (!filter_var($k, FILTER_VALIDATE_INT)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_IP': | |
if (!filter_var($k, FILTER_VALIDATE_IP)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_REGEXP': | |
if (!filter_var($k, FILTER_VALIDATE_REGEXP)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
case 'FILTER_VALIDATE_URL': | |
if (!filter_var($k, FILTER_VALIDATE_URL)) { | |
$returnArray[$key] = 'error'; | |
} | |
break; | |
} | |
} | |
} else { | |
if ($value == '' || strtolower($value) == $key) { | |
$returnArray[$key] = 'error'; | |
} | |
} | |
} | |
if (is_array($returnArray)) { | |
return $returnArray; | |
} else { | |
return true; | |
} | |
} | |
public static function sendMail($from, $to, $document, $subject, $params, $logging=false) | |
{ | |
$mail = new Pimcore_Mail('UTF-8'); | |
$mail->addTo($to); | |
$mail->setDocument($document); | |
$mail->setSubject($subject); | |
$mail->setFrom($from); | |
$mail->setParams($params); | |
if($logging){ | |
$mail->disableLogging(); | |
} | |
$mail->send(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment