Last active
March 22, 2016 12:22
-
-
Save olafgleba/e838fc5ecf90c309842e to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Init vars | |
$out = ''; | |
// Temp upload path for file uploads | |
$upload_path = $config->uploadTmpDir; | |
// create form | |
$form = $modules->get("InputfieldForm"); | |
$form->action = "./"; | |
$form->method = "post"; | |
$form->attr("enctype", "multipart/form-data"); | |
$form->attr("id+name",'operating-expenses-itemization-form'); | |
$field = $modules->get("InputfieldMarkup"); | |
$field->markupText = "<h4>Belege hochladen</h4><p>Bitte reichen Sie Kopien der Darlehensauszüge | |
ein.</p><p>Erlaubte Dateiformate: <b>JPG</b> / <b>PNG</b> / <b>PDF</b><br />Maximale Dateigröße: | |
<b>2 mb</b> (pro Datei)</p>"; | |
$fieldsetFinanzierungPrivat->append($field); | |
$field = $modules->get("InputfieldFile"); | |
$field->skipLabel = Inputfield::skipLabelBlank; | |
$field->description = ""; | |
$field->required = 0; | |
$field->attr("name+id", 'private_expenses_documents_1'); | |
$field->destinationPath = $upload_path; | |
$field->extensions = "jpg jpeg png pdf"; | |
$field->maxFiles = 1; | |
$field->maxFilesize = 2*1024*1024; // ~2mb | |
$fieldsetFinanzierungPrivat->append($field); | |
$field = $modules->get("InputfieldFile"); | |
$field->skipLabel = Inputfield::skipLabelBlank; | |
$field->description = ""; | |
$field->required = 0; | |
$field->attr("name+id", 'private_expenses_documents_2'); | |
$field->destinationPath = $upload_path; | |
$field->extensions = "jpg jpeg png pdf"; | |
$field->maxFiles = 1; | |
$field->maxFilesize = 2*1024*1024; // ~2mb | |
$fieldsetFinanzierungPrivat->append($field); | |
$form->append($fieldsetFinanzierungPrivat); | |
$fieldsetBenachtigungsart = $modules->get('InputfieldFieldset'); | |
$fieldsetBenachtigungsart->label = 'Bitte bestätigen Sie folgende Angaben'; | |
$field = $modules->get("InputfieldCheckbox"); | |
$field->label = "Vollständigkeitserklärung"; | |
$field->label2 = " Die Sonderbetriebsausgaben des Vorjahres wurden hiermit vollständig erklärt."; | |
$field->attr('id+name','confirmation_tax'); | |
$field->required = 1; | |
$fieldsetBenachtigungsart->append($field); | |
$form->append($fieldsetBenachtigungsart); | |
$submit = $modules->get("InputfieldSubmit"); | |
$submit->skipLabel = Inputfield::skipLabelBlank; | |
$submit->attr("value","» Sonderbetriebsausgaben verbindlich einreichen"); | |
$submit->attr("id+name","submit"); | |
$form->append($submit); | |
// form was submitted so we process the form | |
if($input->post->submit) { | |
// user submitted the form, process it and check for errors | |
$form->processInput($input->post); | |
// Workaround to get errors from the WireUpload used by the file field | |
// Refering to https://gist.github.com/somatonic/5236008 | |
if($form->get("private_expenses_documents_1")->getWireUpload()->getErrors()){ | |
$errors = $form->get("private_expenses_documents_1")->getWireUpload()->getErrors(); | |
foreach($errors as $error) $form->get("private_expenses_documents_1")->error($error); | |
} | |
if($form->get("private_expenses_documents_2")->getWireUpload()->getErrors()){ | |
$errors = $form->get("private_expenses_documents_2")->getWireUpload()->getErrors(); | |
foreach($errors as $error) $form->get("private_expenses_documents_2")->error($error); | |
} | |
// File uploads | |
// Init vars | |
$files = array(); | |
$uploaded_documents = array(); | |
if (empty($files)) { | |
// collect all file upload fields | |
$files[] = explode("|", $form->get("private_expenses_documents_1")->value); | |
$files[] = explode("|", $form->get("private_expenses_documents_2")->value); | |
// Iterate throught files array and build documents array | |
foreach($files as $file){ | |
foreach($file as $_file){ | |
if($_file && file_exists($upload_path . $_file)){ | |
$uploaded_documents[] = $upload_path . $_file; | |
} | |
} | |
} | |
} | |
if($form->getErrors()) { | |
$out .= "<div><h3>Das Formular enthält Fehler!</span></h3></p></div>"; | |
// The form is processed and populated | |
// but contains errors | |
$out .= $form->render(); | |
} else { | |
// PDF Generation, send mail (with generated PDF plus | |
// files as attachment (Variable $uploaded_documents)) | |
} | |
} else { | |
// Render out form without processing | |
$out .= $form->render(); | |
} | |
// Ausgabe | |
echo $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment