Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2013 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5517845 to your computer and use it in GitHub Desktop.
Save anonymous/5517845 to your computer and use it in GitHub Desktop.
<?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()
$errors = array();
if(!count($files)) {
$errors['contact_photo'] = "Sorry, but you need to add a photo!";
}
if(empty($errors)){
// 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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment