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!

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


Form validation not working on Safari, but it does work on Chrome?

Form validation not working on Safari, but it does work on Chrome? Can someone please explain why form validation doesn't work on certain browsers? the message goes through even though the @ sign is missing. I do get an alert on Chrome.

Is there a solution to this?

Here it is Sergey :


// ------------------------------ index.php


require __DIR__ . '/vendor/autoload.php';

//use Monolog\Logger;
//use Monolog\Handler\StreamHandler;
//$log = new Logger('name');
//$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING));

$app = new \Slim\Slim( array(
  'view' => new \Slim\Views\Twig()

$view = $app->view();
$view->parseOptions = array(
    'debug' => true

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),

$app->get('/', function () use($app){

$app->get('/contact', function () use($app){

$app->post('/contact', function () use($app){


// ------------------------------------------------------- contact. twig

{% extends 'main.twig' %}

{% block content %}
      <h2>Ralph Waldo Emerson</h2>

      <p>Unfortately, Ralph Waldo Emerson has been deceased for over 100 years so he's not particularly expediant at replying to email but you can make an attempt below. However, if you require face to gravestone contact you can visit his remains at:</p>
        <h4>Sleepy Hollow Cemetery</h4>
        <p>34 Bedford Street<br>
        Concord, MA 01742, United States<br>
      <a href="https://www.google.com/maps/place/Sleepy+Hollow+Cemetery/@42.464126,-71.343098,15z/data=!4m2!3m1!1s0x0:0x9c41d0f83df689a6?sa=X&ei=ZCgLVZb5Io_hoASc7oHwCQ&ved=0CH0Q_BIwCw">Google Map</a></p>

      <form action="" method="post">
          <input name="name" type="text" placeholder="Full Name">
          <input name="email" type="email" placeholder="Email Address" required>
          <textarea name="msg" placeholder="Your message..."></textarea>
        <input type="submit" class="button">
 {% endblock content %}

// ------------------------------- main.twig

<!doctype html>

<html lang="en">
  {% block head %}
    <meta charset="utf-8">
    <title>{% block title %}Ralph Waldo Emerson {% endblock title %}</title>
    <meta name="description" content="Ralph Waldo Emerson">
    <meta name="author" content="Treehouse">
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/master.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="js/global.js"></script>
  {% endblock head %}

  <div id="feedback" class="success">
    <p>You're reading all about Emerson.</p>

    <h1>Ralph Waldo Emerson</h1>
      <a href="{{ baseUrl() }}" class="selected">About</a>
      <a href="{{ siteUrl('/contact') }}">Contact</a>

  <div class="emerson">
    {% block hero %}<img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson">{% endblock hero %}

   {% block content %}
   {% endblock content %} 

    {% block footer %}
      <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p>
        <a href="{{ baseUrl() }}" class="selected">About</a>
        <a href="{{ siteUrl('/contact') }}">Contact</a>
    {% endblock footer %}


2 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

It looks fine, except zou did not provide path in form:

<form action="" method="post">

As I see from your code, you are expecting data at /contact:

$app->post('/contact', function () use($app){

So you should provide this path in action attribute

<form action="/contact" method="post">

Thanks, Sergey!