Jump to content

Robert_Craig

Members
  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Robert_Craig

  • Rank
    Member

Recent Profile Visitors

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

  1. 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
  2. <?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.
  3. 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?
  4. 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?
  5. 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.
  6. 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?
  7. 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 }
  8. 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>
  9. That is exactly what I was thinking. But with my limited knowledge of coding it was the only way I could come up with a work around. I have been on People Per Hour and found someone who said they can do it for $5 but not quite sure how they will do it and also they was not from the UK so could not understand me properly.
  10. Thank you for the replies. As I am a total beginner I found your helpful recommendations too difficult for me to implement on my own so I therefore went for the easier way of just adding another field in my database called tags2. So now my code looks like this: "SELECT * FROM videos WHERE title LIKE '%$search_query%' OR tags LIKE '%$search_query%' OR tags2 '%$search_query%' ORDER BY title"; The problem I am getting now is that if someone searches for something in either tags or tags2 the search works but if they search for both it returns nothing. I have tried to add tags AND tags2 but that didn't work either.
  11. Thanks for correcting me with regards to the correct terminology. Yes you are correct, currently the tags field has more than a single descriptive term. How do you recommend I add this information in my database? I am a total beginner in PHP so please excuse the ignorance but where you have written '%$word1' '%$word2' etc. Is this where I would replace the word 'word' with one keyword?
  12. I am having an issue with my website SQL Search. In my database I have a row called 'Tags' and within that field I enter any keywords that someone would be likely to search. The problem I am having is that I cannot get it to work the way I would like. For example in the tags row I have: 1) Red Dress 2) Blue Dress My code is SELECT * FROM videos WHERE tags RLIKE '[[:<:]]{$search_query}[[:>:]]' Now with this if someone searches red dress or even just red, then it will show the correct results. However if someone searches dress red it will not show any thing because in my tags field in the database, I have it entered as Red Dress in that order. I have tried this code: SELECT * FROM videos WHERE tags LIKE '%$search_query%' But this means the user can search words like dres and the results for dress will appear or even just the letter 'e' and then blue and red will appear because they both have the letter 'e' in them. What I would like is for the RLIKE code to work as it is but just be able to search any word from the tags row in my database, rather than in a particular order. If anyone can help it would be most appreciated, thank you. Robert
  13. Wow! Thank you so much Barand. I have made the few changes that you suggested and it is all working perfectly. Thank you again
  14. Thanks mac_gyver and Barand for the replies. Barand I understand what you are saying and I will do some tweaks with my little php knowledge and get back to you if it works. What about if I wanted to make active='1 AND 2' but not 0. I have tried AND but that doesn't work. What would be the correct 'term' (if that's the right word) to use in that instance?
  15. I think it will make more sense if I add the whole code here. I changed the code to how you mentioned but it still didn't work. I'm guessing because you did not see the code you could not get a full understanding. <?php /* Including the config.php file, which is holding the configuration variable details */ include_once 'lectures-config.php'; /* Establishing connection with database and returning connection object */ function connect_db(){ $connection = mysqli_connect( DB_HOST, DB_USER, DB_PASS, DB_NAME ); if(!$connection){ die('Failed to establish connection with database!'); } return $connection; } /* Getting the count of total rows in the videos table */ function get_rows_count(){ $connection = connect_db(); $sql = "SELECT COUNT(*) AS `row_count` FROM `videos`"; $result = mysqli_query($connection, $sql); $result = mysqli_fetch_assoc($result); return $result['row_count']; } /* Creating pagination links */ function create_pagination(){ global $per_page_pagination_links; global $per_page_records; $start = 0; $end = 0; $connection = connect_db(); $page_number = (isset($_GET['page']) AND !empty($_GET['page']))?intval($_GET['page']):1; $pagination_buttons = $per_page_pagination_links; if(($pagination_buttons%2) == 0){ die('Error: The count of pagination buttons should be an odd number'); } $rows = get_rows_count(); $last_page = ceil($rows/$per_page_records); $pagination = '<ul>'; if($page_number < 1 OR $page_number == '' OR $page_number == NULL){ $page_number = 1; } else if($page_number > $last_page){ $page_number = $last_page; } $half = floor($pagination_buttons/2); if( $pagination_buttons < $last_page ){ if( $page_number == 1 ){ // echo 1; for($i=1; $i<=$pagination_buttons; $i++){ if($i == $page_number){ $pagination .= '<li class="current"><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } else{ $pagination .= '<li><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } } $pagination .= '<li><a href="index.php?page=' . ($pagination_buttons+1) . '">»</a></li>'; } else if( $page_number > 1 ){ // echo 2; if($page_number > $half){ $start = abs($page_number - $half); $end = abs($page_number + $half); } else{ $start = 1; $end = $pagination_buttons; } //$start = abs($page_number - $half); if( $end < $last_page){ // echo 2.1; $pagination .= '<li><a href="index.php?page=' . ($start - 1) . '">«</a></li>'; for($i=$start; $i<=$end; $i++){ if($i == $page_number){ $pagination .= '<li class="current"><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } else{ $pagination .= '<li><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } } $pagination .= '<li><a href="index.php?page=' . ($end + 1) . '">»</a></li>'; } else if( $end == $last_page ){ // echo 2.2; $pagination .= '<li><a href="index.php?page=' . ($start - 1) . '">«</a></li>'; for($i=$start; $i<=$end; $i++){ if($i == $page_number){ $pagination .= '<li class="current"><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } else{ $pagination .= '<li><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } } } else if( $end > $last_page ){ // echo 2.3; $pagination .= '<li><a href="index.php?page=' . ($start - 1) . '">«</a></li>'; $start = abs($last_page - $pagination_buttons)+1; for($i=$start; $i<=$last_page; $i++){ if($i == $page_number){ $pagination .= '<li class="current"><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } else{ $pagination .= '<li><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } } } } } else if( $pagination_buttons >= $last_page ){ // echo 3; for($i=1; $i<=$last_page; $i++){ if($i == $page_number){ $pagination .= '<li class="current"><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } else{ $pagination .= '<li><a href="index.php?page=' . $i . '">' . $i . '</a></li>'; } } } $pagination .= '</ul>'; echo $pagination; } /* Selecting and displaying content from database */ function get_contents(){ global $per_page_records; $connection = connect_db(); $page_number = (isset($_GET['page']) AND !empty($_GET['page']))?intval($_GET['page']):1; $rows = get_rows_count(); $last_page = ceil($rows/$per_page_records); if($page_number < 1 OR $page_number == '' OR $page_number == NULL){ $page_number = 1; } else if($page_number > $last_page){ $page_number = $last_page; } $page_number--; $page_number *= $per_page_records; $sql = "SELECT * FROM `videos` WHERE active='1' ORDER BY timestamp DESC LIMIT {$page_number},{$per_page_records}"; $result = mysqli_query($connection, $sql); $num_rows = mysqli_num_rows($result); if($num_rows){ $str = ''; while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $str .= '<div class="col-sm-6 video-outer equal-height"><div class="video-block"><a href="' . $row['url'] . '"><img src="' . $row['image'] . '" alt="' . $row['title'] . '"></a> <ul> <li> <a href="' . $row['url'] . '"><h3>' . $row['title'] . '</h3></a>' . $row['linebreak'] . ' </li> <li>' . $row['speaker'] . '</li> <li><strong>Language:</strong> ' . $row['language'] . '</li> <li><strong>Date:</strong> ' . $row['date'] . '</li> <li><strong>Running Time:</strong> ' . $row['runningtime'] . '</li> <li><strong>Video Size:</strong> ' . $row['videosize'] . '</li> <li><strong>Audio Size:</strong> ' . $row['audiosize'] . '</li> <li> </li> </ul> </div> </div>'; } echo $str; } else{ echo '<p>Sorry no records exsit</p>'; } } ?>
×
×
  • 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.