title: google recaptcha nodejs app
body: <p>Ok so I am trying to implement Google Recaptcha into my register page for my app.  Everything on the front end seems to work as far as it loads the page and when I click "I am not a robot" it asks me to verify images and then... when I click submit, It tells me to "Please select captcha" and it redirects me back to the register page. Thats how I have the code setup if someone doesn't select the captcha checkmark but I cannot figure out why it won't continue and create the user.  Here is the code... </p>
  
  <pre><code>// handle signup logic
  router.post("/register", function(req, res) {
    if(req.body.captcha === undefined || req.body.captcha === "" || req.body.captcha === null){
        req.flash("error", "Please select captcha");
        return res.redirect("/register");
      }
      // secret key
      var secretKey = process.env.CAPTCHA;
      // Verify URL
      var verifyURL = `https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&amp;response=${req.body.captcha}&amp;remoteip=${req.connection.remoteAddress}`;
      // Make request to Verify URL
      request(verifyURL, (err, response, body) =&gt; {
        // if not successful
        if(body.success !== undefined &amp;&amp; !body.success){
          req.flash("error", "Captcha Failed");
          return res.redirect("/register");
        }
  
        // if successful
        upload(req, res, function(err) {
          if(err){
            console.log(err.message);
            req.flash("error", err.message);
            return res.redirect("/register");
         }
         var newUser = new User({
           username: req.body.username,
           firstName: req.body.firstName,
           lastName: req.body.lastName,
           email: req.body.email,
           bio: req.body.bio
         });
  
         if(typeof req.file !== "undefined") {
           newUser.avatar = '/uploads/userImg/' + req.file.filename;
         } else {
           newUser.avatar = '/uploads/userImg/no-image.png';
         }
         console.log(newUser);
         if(req.body.adminCode === process.env.ADMINCODE) {
           newUser.isAdmin = true;
        }
  
        if(req.body.answer !== process.env.SECRET){
          req.flash("error", "answer the question");
          return res.redirect("back");
        } else {
          User.register(newUser, req.body.password, function(err, user){
            if(err){
              console.log(err.message);
              return res.render("register", {error: err.message});
            }
            passport.authenticate("local")(req, res, function(){
              req.flash("success", "Welcome to Let's Camp " + user.username);
              res.redirect("/campgrounds"); 
            }); 
          });
        }
      });
    });
  
   });
  
  &lt;% include ./partials/header %&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="col-md-8 col-md-offset-2"&gt;
        &lt;form id="register" action="/register" method="post" enctype="multipart/form-data"&gt;
          &lt;h1 class="text-center"&gt;Sign Up&lt;/h1&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-4 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="firstName"&gt;First Name&lt;/label&gt;
            &lt;input id="firstName" class="form-control" type="text" id="firstName" name="firstName" placeholder="First Name*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-md-4 col-md-offset-0 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="lastName"&gt;Last Name&lt;/label&gt;
            &lt;input id="lastName" class="form-control" type="text" id="lastName" name="lastName" placeholder="Last Name*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-4 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="email"&gt;Email&lt;/label&gt;
            &lt;input id="email" class="form-control" type="email" id="email" name="email" placeholder="Email*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-md-4 col-md-offset-0 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="avatar"&gt;Avatar Image URL&lt;/label&gt;
            &lt;input id="avatar" class="form-control" type="file" name="avatar"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
       &lt;div class="col-md-4 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="username"&gt;Username&lt;/label&gt;
            &lt;input id="username" class="form-control" type="text" id="username" name="username" placeholder="Username*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-md-4 col-md-offset-0 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="password"&gt;Password&lt;/label&gt;
            &lt;input id="password" class="form-control" type="password" id="password" name="password" placeholder="Password*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-8 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="bio"&gt;Bio&lt;/label&gt;
            &lt;textarea id="bio" class="form-control" type="bio" name="bio" rows="5" placeholder="Write a short description of yourself and what you enjoy about camping."&gt;&lt;/textarea&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-4 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="adminCode"&gt;Admin Code&lt;/label&gt;
            &lt;input id="adminCode" class="form-control" type="text" name="adminCode" placeholder="Admin Code"&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="col-md-4 col-md-offset-0 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="number"&gt;Enter: Answer&lt;/label&gt;
            &lt;input id="number" class="form-control" type="text" id="answer" name="answer" placeholder="Answer*" required&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-4 col-md-offset-4"&gt;
          &lt;div class="g-recaptcha form-group" data-sitekey="6LduxzsUAAAAAAoten8FA_zg12PjA3QfSjF5vFvY"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-8 col-md-offset-2 col-xs-8 col-xs-offset-2"&gt;
          &lt;div class="form-group"&gt;
            &lt;button class="btn btn-lg btn-primary btn-block"&gt;Sign Up!&lt;/button&gt;
          &lt;/div&gt;
          &lt;a href="/campgrounds"&gt;Go Back&lt;/a&gt;
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-12 col-xs-8 col-xs-offset-2"&gt;
              &lt;p class="text-center"&gt;&lt;strong&gt;*&lt;/strong&gt; indicates a required field.&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;% include ./partials/footer %&gt;
  </code></pre>