Page 1 of 1

Getting a Form to Work + reCAPTCHA

Posted: Thu Jul 05, 2012 10:18 pm
by kremo5le
Hi guys,

Learning PHP at the moment. :P

My form isn't working. I want a form that is extremely simple like this one and that works with reCAPTCHA.

1. The form needs to have a simple empty field check. As it is now, there are some form checks but obviously something isn't right because it goes through anyway. The messages you see should only be shown depending on what's going on.

2. I cannot make reCAPTCHA work.

Any help will be appreciated. :D

Code: Select all

<!-- PHP Code -->
            	<?php
					$name = $_POST['name'];
                    $email = $_POST['email'];
                    $message = $_POST['message'];
                    $from = 'From: mysite.com'; 
                    $to = 'sample@my.email.com'; 
                    $subject = 'you got an alien message from outer space';
                            
                    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
                              
                    if ($_POST['submit']) {
                        if (mail ($to, $subject, $body, $from)) { 
                            echo '<h5>Dude, your message has been sent!</h5>';
                        } else { 
                            echo '<h5>Something went wrong, go back and try again!</h5>'; 
                        }
						if ($email == "") {
                        echo "<h5>Hey, you must enter an e-mail address!</h5>";
                        
                        } 
                    }
                    
                
                    
                    ?>
            <!-- PHP Code -->
			<div id="talk_form">
       	    <form method="post" action="talk.php">
        			<fieldset>
                    <label>name</label>
                    <input name="name" type="text" placeholder="What's your name?">
                            
                    <label>email</label>
                    <input name="email" type="email" placeholder="What's your email?">
                            
                    <label>message</label>
            		<textarea name="message" placeholder="m., blah, blah, blah..."></textarea>
                    
                    <script type="text/javascript"
                         src="http://www.google.com/recaptcha/api/challenge?k=my_key">
                    </script>
                      <noscript>
                         <iframe src="http://www.google.com/recaptcha/api/noscript?k=my_key"
                             height="300" width="500"></iframe><br>
                         <textarea name="recaptcha_challenge_field" rows="3" cols="40">
                         </textarea>
                         <input type="hidden" name="recaptcha_response_field"
                             value="manual_challenge">
                      </noscript>
                         <br />
             		<input id="submit" name="submit" type="submit" value="Send!">
                    </fieldset>  
            </form>
            </div>

Re: Getting a Form to Work + reCAPTCHA

Posted: Fri Jul 06, 2012 5:37 am
by social_experiment
http://www.thesitewizard.com/general/ad ... ript.shtml
Have a look at this url.
kremo5le wrote:The form needs to have a simple empty field check. As it is now, there are some form checks but obviously something isn't right because it goes through anyway. The messages you see should only be shown depending on what's going on.
The problem is that the script sends the email (or tries to) as soon as the button is clicked.

Code: Select all

<?php
 //
 if (isset($_POST['button'])) {
   $email = $_POST['email'];
   $message = $_POST['message'];
   $from = 'From: mysite.com'; 
   $to = 'sample@my.email.com'; 
   $subject = 'you got an alien message from outer space';

   // check if these fields contain data, if either is blank, define $errAry and add
   // and element with an error message to it
   if ($email == '' || $message == '') { $errAry[] = 'No email address or message given.'; }

   // test if $errAry is an array; if so, a field was left blank
   if (is_array($errAry)) {
     foreach ($errAry as $errMsg) {
         echo $errMsg;
     }
   }
   else {
      // no errors because $errAry isn't an array so you can
      // send the email
      if (mail ($to, $subject, $body, $from)) { 
          echo '<h5>Dude, your message has been sent!</h5>';
       } else { 
          echo '<h5>Something went wrong, go back and try again!</h5>'; 
       } 
   }
?>
hth

Re: Getting a Form to Work + reCAPTCHA

Posted: Fri Jul 06, 2012 12:50 pm
by kremo5le
Hi there,

I just spent the time setting this up. First of all thank you for such a great tool. Now, even though I do not want a form that opens an error and a thank you page, I can figure that later. Right now I am getting this error:

Code: Select all

Fatal error: Call to undefined function recaptcha_check_answer() in /my/path/structure/form.php on line 53
I can PM you form.php if you'd like. THANKS! :D