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 trial

PHP Building Websites with PHP Contact Form & Sending Email Testing For POST Data

Thomas Pane
Thomas Pane
7,804 Points

Creating an array for longer Forms:

Is this the correct code for doing a for each loop on a variable array instead of checking if each variable is empty through a && comparison?:

$app->post('/press-contact' function() use($app) { $name = $app->request->post('name'); $email = $app->request->post('email'); $msg = $app->reguest->post('msg'); $formArray = array($name, $email, $msg); if (foreach($formArray as $input) {!empty($input)}) {

} else {

}

});