174 lines
7.0 KiB
PHP
Executable File
174 lines
7.0 KiB
PHP
Executable File
<?php
|
|
use fileuploader\server\FileUploader;
|
|
use phpformbuilder\Form;
|
|
use phpformbuilder\Validator\Validator;
|
|
|
|
define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR));
|
|
|
|
/* =============================================
|
|
start session and include form class
|
|
============================================= */
|
|
|
|
session_start();
|
|
include_once ROOT . '/phpformbuilder/Form.php';
|
|
|
|
// include the fileuploader
|
|
include_once ROOT . '/phpformbuilder/plugins/fileuploader/server/class.fileuploader.php';
|
|
|
|
/* =============================================
|
|
validation if posted
|
|
============================================= */
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('cv-submission-form') === true) {
|
|
// create validator & auto-validate required fields
|
|
$validator = Form::validate('cv-submission-form');
|
|
|
|
// additional validation
|
|
$validator->email()->validate('user-email');
|
|
|
|
// check for errors
|
|
if ($validator->hasErrors()) {
|
|
$_SESSION['errors']['cv-submission-form'] = $validator->getAllErrors();
|
|
} else {
|
|
/* Send email with attached file(s) */
|
|
|
|
$path = ROOT . '/file-uploads/';
|
|
$attachments = array();
|
|
if (isset($_POST['cv']) && !empty($_POST['cv'])) {
|
|
$cv = FileUploader::getPostedFiles($_POST['cv']);
|
|
foreach ($cv as $f) {
|
|
$attachments[] = $path . $f['file'];
|
|
}
|
|
$attachments = implode(', ', $attachments);
|
|
}
|
|
|
|
$email_config = array(
|
|
'sender_email' => 'contact@phpformbuilder.pro',
|
|
'sender_name' => 'Php Form Builder',
|
|
'recipient_email' => addslashes($_POST['user-email']),
|
|
'subject' => 'Php Form Builder - CV Submission Form',
|
|
'attachments' => $attachments,
|
|
'filter_values' => 'cv-submission-form, cv'
|
|
);
|
|
$sent_message = Form::sendMail($email_config);
|
|
Form::clear('cv-submission-form');
|
|
}
|
|
}
|
|
|
|
/* ==================================================
|
|
The Form
|
|
================================================== */
|
|
|
|
$form = new Form('cv-submission-form', 'horizontal', 'novalidate', 'foundation');
|
|
// $form->setMode('development');
|
|
$form->setCols(3, 9);
|
|
$form->startFieldset('CV Submission');
|
|
$form->addHtml('<h3>Do you want to work with us? <small>Please fill in your details below</small>.</h3><p> </p>');
|
|
$form->addIcon('user-name', '<i class="input-group-label fi-torso"></i>', 'before');
|
|
$form->addInput('text', 'user-name', '', 'Name', 'class=input-group-field, required');
|
|
$form->addIcon('user-first-name', '<i class="input-group-label fi-torso"></i>', 'before');
|
|
$form->addInput('text', 'user-first-name', '', 'Firstname', 'class=input-group-field, required');
|
|
$form->addIcon('user-email', '<i class="input-group-label fi-mail"></i>', 'before');
|
|
$form->addInput('email', 'user-email', '', 'Email', 'class=input-group-field, required');
|
|
$form->addInput('text', 'position-applying-for', '', 'Position Applying For');
|
|
$form->addPlugin('tinymce', '#additional-information', 'contact-config');
|
|
$form->addTextarea('additional-information', '', 'Additional Information');
|
|
|
|
$form->addHelper('3 files max. Accepted File Types : .pdf, .doc[x], .xls[x], .txt', 'cv');
|
|
|
|
// reload the previously posted file if the form was posted with errors
|
|
$current_file = '';
|
|
if (isset($_POST['cv']) && !empty($_POST['cv'])) {
|
|
$posted_file = FileUploader::getPostedFiles($_POST['cv']);
|
|
$current_file_path = ROOT . '/file-uploads/';
|
|
$current_file_name = $posted_file[0]['file'];
|
|
if (file_exists($current_file_path . $current_file_name)) {
|
|
$current_file_size = filesize($current_file_path . $current_file_name);
|
|
$current_file_type = mime_content_type($current_file_path . $current_file_name);
|
|
$current_file = array(
|
|
'name' => $current_file_name,
|
|
'size' => $current_file_size,
|
|
'type' => $current_file_type,
|
|
'file' => '/file-uploads/' . $current_file_name, // url of the file
|
|
'data' => array(
|
|
'listProps' => array(
|
|
'file' => $current_file_name
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
$fileUpload_config = array(
|
|
'upload_dir' => '../../../../../file-uploads/', // the directory to upload the files. relative to phpformbuilder/plugins/fileuploader/default/php/ajax_upload_file.php
|
|
'limit' => 3, // max. number of files
|
|
'file_max_size' => 2, // each file's maximal size in MB {null, Number}
|
|
'extensions' => ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'txt'],
|
|
'debug' => true // log the result in the browser's console and shows an error text on the page if the uploader fails to parse the json result.
|
|
);
|
|
$form->addFileUpload('file', 'cv', '', 'Upload your CV <br>& Other Testmonials <br>(e.g Certificates)', '', $fileUpload_config, $current_file);
|
|
|
|
$form->addBtn('submit', 'submit-btn', 1, 'Submit CV', 'class=success button');
|
|
$form->endFieldset();
|
|
|
|
// jQuery validation
|
|
$form->addPlugin('formvalidation', '#cv-submission-form');
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Foundation CV Submission Form - How to create PHP forms easily</title>
|
|
<meta name="description" content="Foundation Form Generator - how to create a CV Submission Form with Php Form Builder Class">
|
|
<link rel="canonical" href="https://www.phpformbuilder.pro/templates/foundation-forms/cv-submission-form.php" />
|
|
|
|
<!-- Foundation CSS -->
|
|
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet">
|
|
|
|
<!-- foundation icons -->
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css">
|
|
<?php
|
|
|
|
/* =============================================
|
|
CODE PREVIEW - REMOVE THIS IN YOUR FORMS
|
|
============================================= */
|
|
|
|
include_once '../assets/code-preview-head.php';
|
|
?>
|
|
<?php $form->printIncludes('css'); ?>
|
|
</head>
|
|
<body>
|
|
<h1 class="text-center">Php Form Builder - CV Submission Form<br><small>with File upload and Rich Text Editor</small></h1>
|
|
<div class="grid-container">
|
|
<div class="grid-x grid-padding-x">
|
|
<div class="small-10 small-offset-1 medium-8 medium-offset-2 cell">
|
|
<?php
|
|
if (isset($sent_message)) {
|
|
echo $sent_message;
|
|
}
|
|
$form->render();
|
|
?>
|
|
</div>
|
|
</div>
|
|
<!-- jQuery -->
|
|
<script src="//code.jquery.com/jquery.min.js"></script>
|
|
<?php
|
|
$form->printIncludes('js');
|
|
$form->printJsCode();
|
|
?>
|
|
<?php
|
|
|
|
/* =============================================
|
|
CODE PREVIEW - REMOVE THIS IN YOUR FORMS
|
|
============================================= */
|
|
|
|
include_once '../assets/code-preview-body.php';
|
|
?>
|
|
</div>
|
|
</body>
|
|
</html>
|