Created
May 4, 2013 10:45
-
-
Save anonymous/5517109 to your computer and use it in GitHub Desktop.
Processwire file for uploading a form submission.
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
<div class="form_container"> | |
<form action="./" method="post" id="registermail" enctype="multipart/form-data"> | |
<!-- USER CREDENTIALS !--> | |
<div class="user_credentials"> | |
<p>Scegli username e password</p> | |
<input type="text" name="username" id="username" maxlenght="20" placeholder="Inserisci il tuo username" /> | |
<input type="password" name="password" id="password" maxlenght="20" placeholder="Scegli la tua password" /> | |
<input type="password" name="verify_password" id="verify_password" maxlenght="20" placeholder="Verifica la tua password" /> | |
<input type="email" name="email" id="email" placeholder="il tuo indirizzo e-mail" /> | |
</div> | |
<!-- USER INFO !--> | |
<div class="user_info"> | |
<p>Qualche tua informazione</p> | |
<select name="provincia" class="select_list"> | |
// My options | |
</select> | |
<select name="genere" class="select_list"> | |
// My options | |
</select> | |
<select name="orientamento" class="select_list"> | |
// My options | |
</select> | |
<input type="file" name="contact_photo" /> | |
</div> | |
<!-- ANNUNCIO !--> | |
<div class="user_annuncio"> | |
<p>Il tuo annuncio (potrai cambiarlo in qualsiasi momento)</p> | |
<textarea name="annuncio" id="annuncio" placeholder="Inserisci il tuo annuncio (di almeno 120 caratteri)" /></textarea> | |
</div> | |
<input type="submit" value="Invia" name="register_submit" id="register_submit" /> | |
</form> |
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 | |
// First, confirm that a submission has been made | |
require_once('../index.php'); | |
$input = wire('input'); | |
$sanitizer = wire('sanitizer'); | |
$config = wire('config'); | |
if ($input->post->register_submit) | |
{ | |
$upload_path = $config->paths->assets . 'uploads/'; | |
// RC: create temp path if it isn't there already | |
if(!is_dir($upload_path)) { | |
if(!wireMkdir($upload_path)) throw new WireException("No upload path"); | |
} | |
// New wire upload | |
$u = new WireUpload('contact_photo'); // References the name of the field in the HTML form that uploads the photo | |
$u->setMaxFiles(5); | |
$u->setOverwrite(false); | |
$u->setDestinationPath($upload_path); | |
$u->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); | |
// execute upload and check for errors | |
$files = $u->execute(); | |
// Run a count($files) test to make sure there are actually files; if so, proceed; if not, generate getErrors() | |
if(!count($files)) { | |
$u->error("Sorry, but you need to add a photo!"); | |
return false; | |
} | |
// Save in the ProcessWire page tree; map submission to the template fields | |
$np = new Page(); // create new page object | |
$np->template = "preview_mails_tmpl"; | |
$np->parent = "/preview_mails/"; | |
// Send all form submissions through ProcessWire sanitization | |
$email = $sanitizer->email($input->post->email); | |
$username = $input->post->username; | |
$password = $input->post->password; | |
$provincia = $input->post->provincia; | |
$genere = $input->post->genere; | |
$orientamento = $input->post->orientamento; | |
$annuncio = $input->post->annuncio; | |
// Match up the sanitized inputs we just got with the template fields | |
$np->of(false); | |
$np->title = $email; | |
$np->email = $email; | |
$np->username = $username; | |
$np->password = $password; | |
$np->provincia = $provincia; | |
$np->genere = $genere; | |
$np->orientamento = $orientamento; | |
$np->annuncio = $annuncio; | |
// Save/create the page | |
$np->save(); | |
// Run photo upload | |
foreach($files as $filename) | |
{ | |
$pathname = $upload_path . $filename; | |
$np->images->add($pathname); | |
$np->message("Added file: $filename"); | |
unlink($pathname); | |
} | |
// Save page again | |
$np->save(); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment