Community Forums › Forums › Archived Forums › Design Tips and Tricks › Javascript in footer of Minimum Pro
Tagged: database, footer, javascript, php
- This topic has 4 replies, 2 voices, and was last updated 7 years, 11 months ago by unklee.
-
AuthorPosts
-
January 2, 2017 at 4:00 am #198586unkleeMember
Hi, last year I transferred a bunch of HTML pages into Minimum Pro pages, successfully I'm pleased to say - except for one thing.
At the bottom of my HTML pages I had a 3-way radio button that allowed readers to give feedback. A javascript file which ran in the HTML page head called a php file which stored the result of the feedback in my database. Using phpMyAdmin I can check the feedback. I am not a javascript programmer, and my php is pretty rudimentary, but it was enough to make that work with a lot of help from the internet.
When I converted the pages to WordPress/Genesis/Minimum Pro, I put the php file under themes/Minimum- Pro, and put the javascript in the footer scripts section of the Genesis Theme settings (people seemed to recommend putting it there rather than in the header), adjusted the link to the php file, and thought that would be OK.
When I try the feedback radio buttons, I get the initial response of the javascript (the buttons disappear and are replaced by a "thank you") but nothing is recorded in the database. I am at a loss to understand what else I must need to change, and would appreciate any advice please. Here are the two scripts:
<script type="text/javascript"> function hresponse(helpfulResponse) { document.getElementById("feedback").innerHTML = ""; document.getElementById("formfeed").innerHTML = "Thank you for your feedback."; var request = false; try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = false; } } } if (!request) { return; } var url = "URL/wp-content/themes/minimum-pro/insertHelpful.php"; request.open("POST", url, true); var page = document.title; var helpful = 'Result='+helpfulResponse +'&Page='+page; request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.send(helpful); } </script>
And this is insertHelpful.php:
<?php if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } $link = mysqli_connect('localhost', '***********', '********', '************'); mysqli_set_charset($link, 'utf8'); if (isset($_POST['Page'])) { $value1 =mysqli_real_escape_string($link, $_POST['Result']); $value2 =mysqli_real_escape_string($link, $_POST['Page']); mysqli_query($link, "INSERT INTO page_helpful (Result, Page, Date) VALUES('$value1','$value2',CURDATE())"); mysqli_close($link); exit(); } ?>
Thanks.
http://www.is-there-a-god.infoJanuary 2, 2017 at 7:54 am #198594Victor FontModeratorFirst off, your JavaScript is written for a Microsoft environment. You are calling ActiveXObjects. ActiveXObject is the key/initial function to enable and reference an "Automation object" in a Microsoft programming environment or the Internet Explorer browser. ActiveX does not exist in a WordPress environment. Even your PHP is very old school. This should all be updated to use Ajax, which works across any technology. Since you're not a developer, you'll probably need to hire someone to do this for you. It should only take a couple of hours to write and test the code. It's not very complicated.
By the way, you should probably change your database userid and password since you posted them publicly in your PHP code.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 2, 2017 at 11:59 am #198608unkleeMemberThanks, I'll see what I can do with that information.
Yes, I woke up in the night and realised with horror that I'd forgotten to take out the password, etc. I'll fix it straight away.
January 2, 2017 at 1:15 pm #198616unkleeMemberIs there any way I can modify the code I posted now?
January 2, 2017 at 2:37 pm #198638unkleeMemberThanks to StudioPress, the password information has been removed. Panic over!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.