Last active
December 28, 2015 04:59
-
-
Save mantismamita/7446379 to your computer and use it in GitHub Desktop.
Front-end Wordpress form with file upload
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 | |
/** | |
* The template used for displaying the jobs form | |
* | |
* @package hostel_mama | |
*/ | |
?> | |
<?php | |
if ($_FILES) { | |
if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
$uploadedfile = $_FILES['file']; | |
$upload_overrides = array( 'test_form' => false ); | |
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); | |
if ( $movefile ) { | |
echo "File is valid, and was successfully uploaded.\n"; | |
var_dump( $movefile); | |
} else { | |
echo "Possible file upload attack!\n"; | |
} | |
} | |
$error_nom = false; | |
$error_prenom = false; | |
$error_voie1 = false; | |
$error_jobs_email = false; | |
$error_cp = false; | |
$error_ville = false; | |
$error_nationality = false; | |
if (isset($_POST['jobs-submit'])) { | |
// Initializes the variables | |
$nom = ''; | |
$prenom = ''; | |
$voie1 = ''; | |
$voie2 = ''; | |
$fixte = ''; | |
$jobs_email = ''; | |
$cp = ''; | |
$ville = ''; | |
$portable = ''; | |
$nationaity = ''; | |
$dob = ''; | |
$c_situ_fami = ''; | |
$situ_pro = ''; | |
$diplome = ''; | |
$c_niveau = ''; | |
$autre_diplome = ''; | |
$autre_niveau = ''; | |
$langue_fr = ''; | |
$langue_1 = ''; | |
$langue_2 = ''; | |
$langue_3 = ''; | |
$c_langue_1 = ''; | |
$c_langue_2 = ''; | |
$c_langue_3 = ''; | |
$pays1 = ''; | |
$duree1 = ''; | |
$motif1 = ''; | |
$pays2 = ''; | |
$duree2 = ''; | |
$motif2 = ''; | |
$pays3 = ''; | |
$duree3 = ''; | |
$motif3 = ''; | |
$currentCount = 2; | |
for($i=1; $i<$currentCount; $i++) { | |
${"poste".$i} = ''; | |
${"de".$i} = ''; | |
${"a".$i} = ''; | |
${"contrat".$i} = ''; | |
${"description".$i} = ''; | |
} | |
$choix1 = ''; | |
$dispode1 = ''; | |
$dispoa1 = ''; | |
$cherche_contrat1 = ''; | |
$description1 = ''; | |
$pretention1 = ''; | |
$loisirs = ''; | |
$comment = ''; | |
$commentaires = ''; | |
if (trim($_POST['nom']) === '') { | |
$error_nom = true; | |
} else { | |
$nom = trim($_POST['nom']); | |
} | |
if (trim($_POST['prenom']) === '') { | |
$error_prenom = true; | |
} else { | |
$prenom = trim($_POST['prenom']); | |
} | |
if (trim($_POST['voie1']) === '') { | |
$error_voie1 = true; | |
} else { | |
$voie1 = trim($_POST['voie1']); | |
} | |
if (trim($_POST['jobs-email']) === '' || !isEmail($_POST['jobs-email'])) { | |
$error_jobs_email = true; | |
} else { | |
$jobs_email = trim($_POST['jobs-email']); | |
} | |
if (trim($_POST['cp']) === '0') { | |
$errorcpdate_res = true; | |
} else { | |
$cp = trim($_POST['cp']); | |
} | |
if (trim($_POST['ville']) === '') { | |
$error_ville = true; | |
} else { | |
$ville = stripslashes(trim($_POST['ville'])); | |
} | |
if (trim($_POST['nationality']) === '') { | |
$error_nationality = true; | |
} else { | |
$nationality = trim($_POST['nationality']); | |
} | |
$voie2 = trim($_POST['voie2']); | |
$fixte = trim($_POST['fixte']); | |
$jobs_email = trim($_POST['jobs-email']); | |
$portable = trim($_POST['portable']); | |
$nationaity = trim($_POST['nationality']); | |
$dob = trim($_POST['dob']); | |
$c_situ_fami = trim($_POST['c_situ_fami']); | |
$situ_pro = trim($_POST['situ_pro']); | |
$diplome = trim($_POST['diplome']); | |
$c_niveau = trim($_POST['c_niveau']); | |
$autre_diplome = trim($_POST['autre_diplome']); | |
$autre_niveau = trim($_POST['autre_niveau']); | |
$c_langue_fr = trim($_POST['c_langue-fr']); | |
$langue_1 = trim($_POST['langue1']); | |
$langue_2 = trim($_POST['langue2']); | |
$langue_3 = trim($_POST['langue3']); | |
$c_langue_1 = trim($_POST['c_langue1']); | |
$c_langue_2 = trim($_POST['c_langue2']); | |
$c_langue_3 = trim($_POST['c_langue3']); | |
$pays1 = trim($_POST['pays1']); | |
$duree1 = trim($_POST['duree1']); | |
$motif1 = trim($_POST['motif1']); | |
$pays2 = trim($_POST['pays2']); | |
$duree2 = trim($_POST['duree2']); | |
$motif2 = trim($_POST['motif2']); | |
$pays3 = trim($_POST['pays3']); | |
$duree3 = trim($_POST['duree3']); | |
$motif3 = trim($_POST['motif3']); | |
for($i=1; $i<$currentCount; $i++) { | |
${"poste".$i} = trim($_POST["poste_$i"]); | |
${"de".$i} = trim($_POST["de_$i"]); | |
${"a".$i} = trim($_POST["a_$i"]); | |
${"contrat".$i} = trim($_POST["contrat_$i"]); | |
${"description".$i} = trim($_POST["description_$i"]); | |
} | |
$choix1 = trim($_POST['choix_1']); | |
$dispode1 = trim($_POST['dispo_de_1']); | |
$dispoa1 = trim($_POST['dispo_a_1']); | |
$cherche_contrat1 = trim($_POST['cherche_contrat_1']); | |
$pretention1 = trim($_POST['pretention_1']); | |
$loisirs = trim($_POST['loisirs']); | |
$comment = trim($_POST['comment']); | |
$commentaires = trim($_POST['commentaires']); | |
// Checks for errors | |
if (!$error_nom && !$error_prenom && !$error_jobs_email && !$error_cp && !$error_ville && !$error_nationality) { | |
// Gets the receiver email from the WP admin panel | |
// change after initial testing! set to manager | |
$receiver_email = get_option('admin_email'); | |
$subject = "Candidature de $prenom . $nom"; | |
$body = "Vous avez un nouveau demande de candidature de la part de $nom" . "pour une poste de $choix1" . PHP_EOL . PHP_EOL; | |
$body .= "E-mail: $jobs_email" . PHP_EOL; | |
$body .= PHP_EOL; | |
$body .= "Nom: $nom" . PHP_EOL; | |
$body .= "Prénom: $prenom" . PHP_EOL; | |
$body .= "Adresse 1: $voie1" . PHP_EOL; | |
$body .= "Adresse 2: $voie2" . PHP_EOL; | |
$body .= "Code Postale: $cp" . PHP_EOL; | |
$body .= "Ville: $ville" . PHP_EOL; | |
$body .= "Téléphone fixte: $portable" . PHP_EOL; | |
$body .= "Téléphone fixte: $fixte" . PHP_EOL; | |
$body .= PHP_EOL; | |
$body .= "Nationalité: $nationaity" . PHP_EOL; | |
$body .= "Date de naissance: $dob" . PHP_EOL; | |
$body .= "Situation familiale: $c_situ_fami" . PHP_EOL; | |
$body .= "Situaltion professionelle: $situ_pro" . PHP_EOL; | |
$body .= PHP_EOL; | |
$body .= "Diplome: $diplome" . PHP_EOL; | |
$body .= "Niveau: $c_niveau" . PHP_EOL; | |
$body .= "Diplome 2: $autre_diplome" . PHP_EOL; | |
$body .= "Niveau 2: $autre_niveau" . PHP_EOL; | |
$body .= PHP_EOL; | |
$body .= "Niveau de français: $c_langue_fr" . PHP_EOL; | |
$body .= "Langue 1: $langue_1" . "niveau: $c_langue_1" . PHP_EOL; | |
$body .= "Langue 2: $langue_2" . "niveau: $c_langue_2" . PHP_EOL; | |
$body .= "Langue 3: $langue_3" . "niveau: $c_langue_3" . PHP_EOL; | |
$body .= PHP_EOL; | |
$body .= "Séjours à l'étranger: $pays1 " . "pour $motif1 " . "pendant $duree1" . PHP_EOL; | |
$body .= "Séjours à l'étranger: $pays2 " . "pour $motif2 " . "pendant $duree2" . PHP_EOL; | |
$body .= "Séjours à l'étranger: $pays3" . "pour $motif3" . "pendant $duree3" . PHP_EOL; | |
for($i=1; $i<$currentCount; $i++) { | |
$body .= "Poste: " . ${"poste".$i}. PHP_EOL; | |
$body .= "De: " . ${"de".$i}. PHP_EOL; | |
$body .= "A: " . ${"a".$i}. PHP_EOL; | |
$body .= "Contrat: " . ${"contrat".$i}. PHP_EOL; | |
$body .= "Description: " . ${"description".$i}. PHP_EOL; | |
$body .= PHP_EOL; | |
} | |
$body .= "Poste recherchée: $choix1" . PHP_EOL; | |
$body .= "Disponibile de: $dispode1" . "a: $dispoa1" . PHP_EOL; | |
$body .= "Cherche contrat: $cherche_contrat1" . PHP_EOL; | |
$body .= "Salaire souhaité: $pretention1" . PHP_EOL; | |
$body .= "Loisirs: $loisirs" . PHP_EOL; | |
$body .= "Reféré par: $comment" . PHP_EOL; | |
$body .= "Commentaires: $commentaires" . PHP_EOL; | |
$headers = "From: $jobs_email" . PHP_EOL; | |
$headers .= "Reply-To: $jobs_email" . PHP_EOL; | |
$headers .= "MIME-Version: 1.0" . PHP_EOL; | |
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL; | |
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL; | |
$attachments = $uploadedfile; | |
// Sends Email if conditions are met | |
if (mail($receiver_email, $subject, $body, $headers, $attachments)) { | |
$jobs_email_sent = true; | |
} else { | |
$jobs_email_sent_error = true; | |
} | |
} | |
} | |
?> | |
<section> | |
<p class="title" data-section-title><a href="#jobs"><?php _e('Jobs', 'my-text-domain' )?></a></p> | |
<div class="content group" data-section-content> | |
<?php if (isset($jobs_email_sent) && $jobs_email_sent == true) : ?> | |
<div data-alert class="alert-box success"> | |
<p><?php _e('Thank you.', 'my-text-domain' )?></p> | |
<p><?php _e('We will respond to your message as quickly as possible.', 'my-text-domain' )?></p> | |
</div> | |
<?php elseif (isset($jobs_email_sent_error) && $jobs_email_sent_error == true) : ?> | |
<div data-alert class="alert-box alert"> | |
<p><?php _e('There was an error!', 'my-text-domain' )?></p> | |
<p><?php _e('Unfortunately, there was an error while trying to send the email. Please try again.', 'my-text-domain' )?></p> | |
</div> | |
<?php else : ?> | |
<div class="panel"><p><?php _e('Please note we only accept applicants for long term employment. Papers justifying the right to work in France are indispensable as is fluent French.', 'my-text-domain' )?></p></div> | |
<form name="cv_online" action="<?php the_permalink(); ?>" method="post" id="cv_online" class="custom" enctype="multipart/form-data" data-abide> | |
<fieldset> | |
<legend>Coordonnées</legend> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<div class="inline"><label for="radio1"><input name="radio1" type="radio" id="radio1" value="madame" CHECKED><span class="inline radio checked"></span> Madame</label> | |
</div> | |
<div class="inline"><label for="radio1"><input name="radio1" type="radio" id="radio1" value="madame"><span class="inline radio"></span> Monsieur</label> | |
</div> | |
</div> | |
</div><!-- end row --> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="nom"> Nom : </label> | |
<input id="nom" name="nom" type="text" required> | |
<small class="error">requis</small> | |
<label for="voie1"> Adresse 1 : </label> | |
<input id="voie1" name="voie1" type="text" required> | |
<small class="error">requis</small> | |
<label for="voie2"> Adresse 2 : </label> | |
<input id="voie2" name="voie2" type="text"> | |
<label for="fixte">Tél fixte : </label> | |
<input id="fixte" name="fixte" type="text" placeholder="01 23 45 67 89"> | |
<label for="jobs-email">E-mail : </label> | |
<input id="jobs-email" name="jobs-email" type="email" required> | |
<small class="error">requis</small> | |
</div> | |
<div class="large-6 columns"> | |
<label for="prenom"> Prénom : </label> | |
<input id="prenom" name="prenom" type="text" required> | |
<small class="error">requis</small> | |
<label for="cp"> Code postale : </label> | |
<input id="cp" name="cp" type="number" required> | |
<small class="error">requis</small> | |
<label for="ville"> Ville: </label> | |
<input id="ville" name="ville" type="text" required> | |
<small class="error">requis</small> | |
<label for="portable">Tél portable : </label> | |
<input id="portable" name="portable" type="text" placeholder="06 05 04 03 02"> | |
</div> | |
</div> | |
</fieldset> | |
<fieldset> | |
<legend>Information personnelle</legend> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="dob">Date de naissance </label> | |
<input type="date" name="dob" id="dob" placeholder="jj/mm/aaaa" /> | |
<label for="c_situ_fami">Situation familiale : </label> | |
<select name="c_situ_fami" ID="c_situ_fami"> | |
<option></option> | |
<option value="celibataire">Celibataire</option> | |
<option value="marie(e)">Marié(e)</option> | |
<option value="pacc(e)">Paccé(e)</option> | |
<option value="divorce(e)">Divorcé(e)</option> | |
<option value="veuf(ve)">Veuf(ve)</option> | |
</select> | |
</div> | |
<div class="large-6 columns"> | |
<label for="nationality"> Nationalité: </label> | |
<input id="nationality" name="nationality" type="text" required> | |
<small class="error">requis</small> | |
<label for="situ_pro">Situation professionelle : </label> | |
<select name="situ_pro" ID="situ_pro"> | |
<option></option> | |
<option value="En poste">En poste</option> | |
<option value="Etudiant">Etudiant</option> | |
<option value="Demandeur d'emploi">Demandeur d'emploi</option></select> | |
</div> | |
</div> | |
</fieldset> | |
<fieldset> | |
<legend>Formation</legend> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="diplome">Diplôme :</label> | |
<input type="text" name="diplome" id="diplome" /> | |
<label for="c_niveau">Niveau d'étude :</label> | |
<select name="c_niveau" ID="c_niveau"> | |
<option></option> | |
<option value='BEP/CAP'>BEP/CAP</option> | |
<option value='BAC'>BAC</option> | |
<option value='Bac+2'>Bac+2</option> | |
<option value='Bac+3'>Bac+3</option> | |
<option value='Bac+4'>Bac+4</option> | |
</select> | |
</div> | |
<div class="large-6 columns"> | |
<label for="autre_diplome">Autre diplôme :</label> | |
<input type="text" name="autre_diplome" id="autre_diplome" /> | |
<label for="autre_niveau">Niveau d'étude :</label> | |
<select name="autre_niveau" ID="autre_niveau" > | |
<option></option> | |
<option value='BEP/CAP'>BEP/CAP</option> | |
<option value='BAC'>BAC</option> | |
<option value='Bac+2'>Bac+2</option> | |
<option value='Bac+3'>Bac+3</option> | |
<option value='Bac+4'>Bac+4</option> | |
</select> | |
</div> | |
</div> | |
</fieldset> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<fieldset> | |
<legend>Langues</legend> | |
<div class="panel no-bottom-padding"> | |
<label for="prenom">Niveau de Français :</label> | |
<select name="c_langue-fr" ID="c_langue-fr"> | |
<option></option> | |
<option value='Langue maternelle'>Langue maternelle</option> | |
<option value='Courant'>Courant</option> | |
<option value='Intermediaire'>Intermediaire</option> | |
</select> | |
</div> | |
<div class="panel no-bottom-padding"> | |
<label for="langue1">Langue 1:</label> | |
<input type="text" name="langue1" id="langue1" /> | |
<select name="c_langue1" ID="c_langue1"> | |
<option></option> | |
<option value='Langue maternelle'>Langue maternelle</option> | |
<option value='Courant'>Courant</option> | |
<option value='Intermediaire'>Intermediaire</option> | |
</select> | |
</div> | |
<div class="panel no-bottom-padding"> | |
<label for="prenom">Langue 2:</label> | |
<input type="text" name="langue2" id="langue2" /> | |
<select name="c_langue2" ID="c_langue2"> | |
<option></option> | |
<option value='Langue maternelle'>Langue maternelle</option> | |
<option value='Courant'>Courant</option> | |
<option value='Intermediaire'>Intermediaire</option> | |
</select> | |
</div> | |
<div class="panel no-bottom-padding"> | |
<label for="prenom">Langue 3:</label> | |
<input type="text" name="langue3" id="langue3" /> | |
<select name="c_langue3" ID="c_langue3"> | |
<option></option> | |
<option value='Langue maternelle'>Langue maternelle</option> | |
<option value='Courant'>Courant</option> | |
<option value='Intermediaire'>Intermediaire</option> | |
</select> | |
</div> | |
</fieldset> | |
</div> <!-- end 6 cols --> | |
<div class="large-6 columns"> | |
<fieldset> | |
<legend>Séjours à l'étranger</legend> | |
<div class="panel"> | |
<label for="pays1">Pays :</label> | |
<input type="text" name="pays1" id="pays1" /> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="duree1">Durée :</label> | |
<input type="text" name="duree1" id="duree1" class="small"/> | |
</div> | |
<div class="large-6 columns"> | |
<label for="motif1">Motif :</label> | |
<select name="motif1" ID="motif1"> | |
<option></option> | |
<option value='professionnel'>professionnel</option> | |
<option value='tourisme'>tourisme</option> | |
<option value='etudes'>etudes</option> | |
</select> | |
</div> | |
</div> | |
</div> | |
<div class="panel"> | |
<label for="pays2">Pays :</label> | |
<input type="text" name="pays2" id="pays2" /> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="duree2">Durée :</label> | |
<input type="text" name="duree2" id="duree2" class="small"/> | |
</div> | |
<div class="large-6 columns"> | |
<label for="motif2">Motif :</label> | |
<select name="motif2" ID="motif2"> | |
<option></option> | |
<option value='professionnel'>professionnel</option> | |
<option value='tourisme'>tourisme</option> | |
<option value='etudes'>etudes</option> | |
</select> | |
</div> | |
</div> | |
</div> | |
<div class="panel"> | |
<label for="pays3">Pays :</label> | |
<input type="text" name="pays3" id="pays3" /> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="duree3">Durée :</label> | |
<input type="text" name="duree3" id="duree3" class="small"/> | |
</div> | |
<div class="large-6 columns"> | |
<label for="motif3">Motif :</label> | |
<select name="motif3" ID="motif3"> | |
<option></option> | |
<option value='professionnel'>professionnel</option> | |
<option value='tourisme'>tourisme</option> | |
<option value='etudes'>etudes</option> | |
</select> | |
</div> | |
</div> | |
</div> | |
</fieldset> | |
</div> | |
</div> <!-- end row --> | |
<fieldset> | |
<legend>Expérience professionnelle</legend> | |
<div class="row repeatingSection"> | |
<div class="large-10 small-11 columns panel inside"> | |
<div class="large-6 columns"> | |
<label for="poste_1">Poste :</label> | |
<input type="text" name="poste_1" id="poste_1"/> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="de_1">De :</label> | |
<input type="date" name="de_1" id="de_1" class="small"/> | |
</div> | |
<div class="large-6 columns"> | |
<label for="a_1">A :</label> | |
<input type="date" name="a_1" id="a_1" class="small"/> | |
</div> | |
</div> | |
<label for="contrat_1">Contrat :</label> | |
<select name="contrat_1" ID="contrat_1" class="small"> | |
<option></option> | |
<option value='CDI'>CDI</option> | |
<option value='CDD'>CDD</option> | |
<option value='stagiaire'>Stagiaire</option> | |
<option value='saisonnier'>Saisonnier</option> | |
</select> | |
</div> | |
<div class="large-6 columns"> | |
<label for="description_1"> Description: </label> | |
<textarea id="description_1" name="description_1" class="lrg-txtarea"></textarea> | |
</div> | |
</div><!-- end repeatingSection --> | |
<div class="large-2 small-12 columns"> | |
<button class="cloneButton small secondary radius indent">+</button> | |
<button class="removeButton small secondary radius indent">−</button> | |
</div> | |
</div> <!-- end row --> | |
</fieldset> | |
<fieldset> | |
<legend>Poste recherchée(s)</legend> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="choix_1">Poste :</label> | |
<select name="choix_1" ID="choix_1"> | |
<option></option> | |
<option value='receptionniste'>Réceptionniste</option> | |
<option value='veilleur'>Veilleur de nuit</option> | |
<option value='caféteriat'>Service petit déjeuner</option> | |
<option value='menage'>Service ménage</option> | |
</select> | |
<div class="row"> | |
<div class="large-6 columns"> | |
<label for="dispo_de_1">Disponible De :</label> | |
<input type="date" name="dispo_de_1" id="dispo_de_1" class="small"/> | |
</div> | |
<div class="large-6 columns"> | |
<label for="dispo_a_1">Disponible jusqu'à :</label> | |
<input type="date" name="dispo_a_1" id="dispo_a_1" class="small"/> | |
</div> | |
</div> | |
<label for="cherche_contrat_1">Contrat recherché :</label> | |
<select name="cherche_contrat_1" ID="cherche_contrat_1" class="small"> | |
<option></option> | |
<option value='CDI'>CDI</option> | |
<option value='CDD'>CDD</option> | |
<option value='stagiaire'>Stagiaire</option> | |
<option value='saisonnier'>Saisonnier</option> | |
</select> | |
</div> | |
<div class="large-6 columns"> | |
<label for="pretention_1">Prétentions salaire (brut/mensuelle) : </label> | |
<textarea id="pretention_1" name="pretention_1"></textarea> | |
</div> | |
</div> <!-- end row --> | |
</fieldset> | |
<fieldset> | |
<legend>Autres informations</legend> | |
<div class="row"> | |
<div class="large-12 columns"> | |
<label for="loisirs"> Loisirs et intérêts : </label> | |
<textarea id="loisirs" name="loisirs"></textarea> | |
<label for="comment">Comment nous avez-vous connu ?</label> | |
<textarea name="comment" id="comment"></textarea> | |
<label for="commentaires">Commentaires additionnelles :</label> | |
<textarea name="commentaires" id="commentaires"></textarea> | |
</div> | |
</div> | |
</fieldset> | |
<fieldset> | |
<legend>Votre CV</legend> | |
<p>Vous pouvez joindre CV et lettre de motivation en utilisant la fonction parcourir <em>format word ou pdf - max 2 Mo</em></p> | |
<input type="file" name="upload_file"> | |
</fieldset> | |
<p class="panel"><em>Nous vous remercions d’avoir déposé votre C.V. auprès de notre établissement.</em></p> | |
<input type="hidden" id="jobs-submit" name="jobs-submit" value="true" /> | |
<input type="submit" name="Submit" value="Envoyer" class="button success radius"> | |
<input type="reset" class="button alert radius" value="Retour"/> | |
</form> | |
<?php endif; ?> | |
</div> | |
</section> <!-- jobs --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment