Jump to content

Robert_Craig

Members
  • Posts

    19
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Robert_Craig's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you Barand for the quick reply and easy explanation.
  2. I am trying to create a math equation inside a variable but I am struggling to achieve the desired result. On one php page I have this: $x = "date('Y')"; $y = "1989"; $description = "In this classic lecture which was delivered over $x - $y years ago, etc etc....."; On my main page I have linked to the above and also $description but the result I am getting is: In this classic lecture which was delivered over date('Y') - 1989 years ago, I want to create a variable so I don't need to go back every year and change the description. Is this possible? Robert
  3. I have no idea. As mentioned above I am a beginner with JS and PHP. After my course in JS (as long as I pass of course) I am planning on doing their PHP course. What I did as a work around was to add a hidden input with the name subject to get it to work on first click
  4. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { function post_captcha($user_response) { $fields_string = ''; $fields = array( 'secret' => '***************SECRET_KEY***************', 'response' => $user_response ); foreach($fields as $key=>$value) $fields_string .= $key . '=' . $value . '&'; $fields_string = rtrim($fields_string, '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify'); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); $result = curl_exec($ch); curl_close($ch); return json_decode($result, true); } $res = post_captcha($_POST['g-recaptcha-response']); if (!$res['success']) { header('Location: robot.php'); } else { $myemail = 'robert.craig@gmail.com'; if ($_SERVER['REQUEST_METHOD']=='POST') { $name = $_POST['name']; $email_address = $_POST['email']; $country = $_POST['country']; $tel = $_POST['tel']; $to = $myemail; $email_subject = "Subscription"; $email_body = "You have received a new message. ". "Here are the details:\n Name: $name \n Email: $email_address \n Country: $country \n Telephone: $tel"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); } $form_result = "<p id='inline-sub'>Subscription received.</p><br><br>"; } } else { ?> <?php } ?> This is the reCAPATCHA code in PHP which I got from an online tutorial. This is the code for the one that requires two clicks to submit.
  5. I just changed the name of the line 9 in the second form (from 'name' to 'subject') and now that form submits on the first click. So what is it in the code that is needing the word 'subject' for it to submit on the first click?
  6. Well spotted Barand. Definitely makes me think twice about the course now. 😊 requinix I have gone through your code and I thought I had it working but then noticed that on some of my forms I have to press the submit button twice before the form submits. On this form it submits fine with just one click: <form action="formmail.php" method="post" id="i-recaptcha"> <div class="g-recaptcha" data-sitekey="****************SITE_KEY****************" data-size="invisible" data-callback="recaptchaSubmit"> </div> <div> <input type="text" name="name" placeholder="Name (Required)" required> </div> <div> <input type="email" name="email" placeholder="Email Address (Required)" required> </div> <div> <input type="text" name="country" placeholder="Country (Required)" required> </div> <div> <input type="tel" name="tel" placeholder="Mobile Number (Optional)"> </div> <div> <input type="text" name="subject" placeholder="Subject (Required)" required> </div> <div> <textarea name="message" placeholder="Message (Required)" required></textarea> </div> <div> <label>Subscribe to updates:</label> <input type="checkbox" name="subscribe" value="Yes" checked> </div> <div><input type="submit" value="Submit"></div> </form> But on this form and similar forms I have to press it twice: <form action="formmail.php" method="post" id="i-recaptcha"> <div class="g-recaptcha" data-sitekey="****************SITE_KEY****************" data-size="invisible" data-callback="recaptchaSubmit"> </div> <div> <label>Name</label> <input type="text" name="name" placeholder="Name (Required)" required> </div> <div> <label>Email Address</label> <input type="email" name="email" placeholder="Email Address (Required)" required> </div> <div> <label>Country</label> <input id="myInput" type="text" name="country" placeholder="Country (Required)" required> </div> <div> <label>Mobile Number</label> <input type="tel" name="tel" placeholder="Mobile Number (Optional)"> </div> <div><input type="submit" value="Join"></div> </form> I don't know if this has anything to do with it but when I remove lines 19, 20, 21 (the Subject input) on the first form above, then I have to also press the submit button twice before it submits. So maybe it has something to do with the subject input not being in any of my other forms?
  7. Thank you requinix. You are right about learning JS. I am actually about to start a JS course at Seer Computing in the UK in about 3 weeks. I will go through your post now and hopefully be able to make sense of it as you have very gratefully added comments on all sections. Thank you again for your help.
  8. My knowledge of JavaScript is nonexistent unfortunately. I am familiar with HTML but a beginner with JS and PHP so I have no idea what to do with that JS code above. Do I just put that code in between <script> </script> tags and place it in my HTML code?
  9. Thank you requinix. From what I understand it ask to remove the reCAPTCHA code from the from button and place it in a div instead. So I now have this code <form action="formail.php" method="post" id="i-recaptcha"> <div class="g-recaptcha" data-sitekey="****************SITE_KEY****************" data-size="invisible" data-callback="onSubmit"> </div> <div> <label>Name</label> <input type="text" name="name" placeholder="Name (Required)" required> </div> <div> <label>Email Address</label> <input type="email" name="email" placeholder="Email Address (Required)" required> </div> <div> <label>Country</label> <input type="text" name="country" placeholder="Country (Optional)"> </div> <div><input type="submit" value="Submit"></div> </form> What I don't understand is what I need to do with this code which is on that link you forwarded $('#form-contact').submit(function (event) { event.preventDefault(); grecaptcha.reset(); grecaptcha.execute(); }); function formSubmit(response) { // submit the form which now includes a g-recaptcha-response input }
  10. Hello I have recently implemented the Google reCAPTCHA v2 on my site. I am using the invisible version which only shows the reCAPTCHA if it thinks it may be a bot. I have noticed that when I added the reCAPTCHA to my site it now disables the HTML5 validation that was working fine before. My form is a standard form which I have included the code below. Is there a way to enable the validation so that it runs before that reCAPTCHA takes control? <form action="formail.php" method="post" id="i-recaptcha"> <div> <label>Name</label> <input type="text" name="name" placeholder="Name (Required)" required> </div> <div> <label>Email Address</label> <input type="email" name="email" placeholder="Email Address (Required)" required> </div> <div> <label>Country</label> <input type="text" name="country" placeholder="Country (Optional)"> </div> <div><input type="submit" value="Submit" class="g-recaptcha" data-sitekey="****************SITE_KEY****************" data-callback="onSubmit"></div> </form>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.