Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMyles Hyson
8,853 PointsBlank Page
I keep getting a blank page after submitting form. Literally copied and pasted the completed project files and it still does this. Can someone help?
<?php
require 'vendor/autoload.php';
date_default_timezone_set('America/New_York');
//$log = new Monolog\Logger('name');
//$log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING));
//$log->addWarning('Oh Noes.');
$app = new \Slim\Slim( array(
'view' => new \Slim\Views\Twig()
));
$view = $app->view();
$view->parserOptions = array(
'debug' => true
);
$view->parserExtensions = array(
new \Slim\Views\TwigExtension(),
);
$app->get('/', function() use($app){
$app->render('about.twig');
})->name('home');
$app->get('/contact', function() use($app){
$app->render('contact.twig');
})->name('contact');
$app->post('/contact', function() use($app){
$name = $app->request->post('name');
$email = $app->request->post('email');
$msg = $app->request->post('msg');
if(!empty($name) && !empty($email) && !empty($msg)) {
$cleanName = filter_var($name, FILTER_SANITIZE_STRING);
$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
$cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING);
} else {
//message the user that there was a problem
$app->redirect('/contact');
}
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance();
$message->setSubject('Email From Our Website');
$message->setFrom(array(
$cleanEmail => $cleanName
));
$message->setTo(array('treehouse@localhost'));
$message->setBody($cleanMsg);
});
$app->run();
Ted Sumner
Courses Plus Student 17,967 PointsEdited to format code. You need the language after the first three ` with no space in between.
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsThere are several places that you might have a problem. The best way to help you is if this is in Workspaces. If so, please post a snapshot by clicking the camera in the upper right corner. Follow the directions until you can copy and paste a URL here.
We need to look at the file structure, main.twig, and .htaccess file to start with.
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsI haven't done this particular course, but is it supposed to display something? Getting a blank page doesn't necessarily mean that the code doesn't work. Try echoing a message somewhere, just for testing purposes.