For some reason this PHP doesn't take place after submitting a form - forms

I have the following HTML +javascript form:
<script>
window.addEventListener("load", function() {
var form = document.getElementById("myform");
var link = document.getElementById("submit-link");
link.addEventListener("click", function(event) {
event.preventDefault();
form.submit();
}, false);
}, false);
</script>
<form action="" method="post" id="myform">
<a id="submit-link" href="http://www.google.com">Submit</a>
</form>
The following CSS code for design:
.ssd {
border: none;
background-color: transparent;
padding: 0;
cursor: pointer;
font-size:89%;
display:inline;
text-decoration: underline;
color: #00c;
}
And this PHP code:
if(isset($_POST['myform'])){
$xmla = new SimpleXMLElement('passwords/' . views . '.xml', 0, true);
$plus = $xmla->goodx;
$result = $plus + 1;
$xmla->goodx = $result;
$xmla->asXML('passwords/' . views . '.xml');
}
Now, Every time that the user clicks on the value "Click", the XML file is supposed to be updated with data, and then redirect to google.com. It works, but when the user places his mouse over the link, he sees the URL of my site, and not google's. any ideas how to solve it?

Use action="" and redirect to the right google.com page.
Look at the google.com URL to know how it works.
Edit:
To see the link in each browser, you will need to use a link and post the form with JavaScript:
<script>
window.addEventListener("load", function() {
var form = document.getElementById("myform");
var link = document.getElementById("submit-link");
link.addEventListener("click", function(event) {
event.preventDefault();
form.submit();
}, false);
}, false);
</script>
<form action="" method="post" id="myform">
<a id="submit-link" href="http://www.google.com">Submit</a>
</form>
This way, the user will see the google link and it will post to your PHP script.

Related

SharpSpring - Prevent form from automatically appearing if user has filled out form (without relying on cookies)

Ok, this is related to the question I asked a short while ago: Silverstripe/PHP/jQuery - Once form has been filled out by user, prevent it from automatically appearing for each visit
Something has changed since then. Per request of the client, the form must not automatically appear if the user has already filled it out and has thus been placed into SharpSpring. Originally, I was creating a cookie on successful form submission using JavaScript. However, the latest concern is that it's not effective enough as cookies are registered only to certain devices and browsers, and users can clear their cookies at any time.
Essentially, the desired result is to prevent the form from automatically appearing if the user has been registered in SharpSpring (a separate domain) without having to rely on cookies.
Has anyone ever attempted something like this, checking to see if a user has submitted a form to another domain?
For reference, here is the form code I have setup:
<?php
/*
Plugin Name: SharpSpring Form Plugin
Description: A custom form plugin that is SharpSpring-compatible and uses HTML, CSS, jQuery, and AJAX
Version: 1.0
*/
define('SSCFURL', WP_PLUGIN_URL . "/" . dirname(plugin_basename(__FILE__)));
define('SSCFPATH', WP_PLUGIN_DIR . "/" . dirname(plugin_basename(__FILE__)));
function sharpspringform_enqueuescripts()
{
wp_enqueue_script('jquery-src', SSCFURL . '/js/jquery.js', array('jquery'));
wp_enqueue_script('jquery-ui', SSCFURL . '/js/jquery-ui.js', array('jquery'));
wp_enqueue_script('boootstrap', SSCFURL . '/js/bootstrap.js', array('jquery'));
wp_localize_script('sharpspringform', 'sharpspringformajax', array('ajaxurl' => admin_url('admin-ajax.php')));
}
add_action('wp_enqueue_scripts', 'sharpspringform_enqueuescripts');
function sharpspringform_show_form()
{
wp_enqueue_style( 'boilerplate', SSCFURL.'/css/boilerplate.css');
wp_enqueue_style( 'bootstrapcss', SSCFURL.'/css/bootstrap.css');
wp_enqueue_style( 'bookregistration', SSCFURL.'/css/Book-Registration.css');
wp_enqueue_style( 'formstyles', SSCFURL.'/css/styles.css');
?>
<div class="mobile-view" style="right: 51px;">
<a class="mobile-btn">
<span class="glyphicon glyphicon-arrow-left icon-arrow-mobile mobile-form-btn"></span>
</a>
</div>
<div class="slider register-photo">
<div class="form-inner">
<div class="form-container">
<form method="post" enctype="multipart/form-data" class="signupForm" id="browserHangFormPV">
<a class="sidebar">
<span class="glyphicon glyphicon-arrow-left icon-arrow arrow"></span>
</a>
<a class="closeBtn">
<span class="glyphicon glyphicon-remove"></span>
</a>
<h2 class="text-center black">Sign up for our newsletter.</h2>
<p class="errors-container light">Please fill in the required fields.</p>
<div class="success">Thank you for signing up!</div>
<div class="form-field-content">
<div class="form-group">
<input class="form-control FirstNameTxt" type="text" name="first_name" placeholder="*First Name"
autofocus="">
</div>
<div class="form-group">
<input class="form-control LastNameTxt" type="text" name="last_name" placeholder="*Last Name"
autofocus="">
</div>
<div class="form-group">
<input class="form-control EmailTxt" type="email" name="email" placeholder="*Email"
autofocus="">
</div>
<div class="form-group">
<input class="form-control CompanyTxt" type="text" name="company" placeholder="*Company"
autofocus="">
</div>
<div class="form-group submit-button">
<button class="btn btn-primary btn-block button-submit" type="button">SIGN ME UP</button>
<img src="/wp-content/plugins/sharpspring-form/img/ajax-loader.gif" class="progress" alt="Submitting...">
</div>
</div>
<br/>
<div class="privacy-link">
<a href="[privacy policy link]" class="already" target="_blank"><span
class="glyphicon glyphicon-lock icon-lock"></span>We will never share your information.</a>
</div>
</form>
<input type="hidden" id="gatewayEmbedID" value="<?php echo get_option( 'pv_signup_sharpspring_ID' ); ?>" />
<script type="text/javascript">
var embedID = document.getElementById("gatewayEmbedID").value;
var __ss_noform = __ss_noform || [];
__ss_noform.push(['baseURI', 'https://app-3QNAHNE212.marketingautomation.services/webforms/receivePostback/[redacted]']);
__ss_noform.push(['form', 'browserHangFormPV', embedID]);
__ss_noform.push(['submitType', 'manual']);
</script>
<script type="text/javascript" src="https://koi-3QNAHNE212.marketingautomation.services/client/noform.js?ver=1.24" ></script>
</div>
</div>
</div>
<?php
}
function sharpspringform_shortcode_func( $atts )
{
ob_start();
sharpspringform_show_form();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'sharpspringform', 'sharpspringform_shortcode_func' );
The form submission code with generates a cookie using JS:
;
(function ($) {
$(document).ready(function () {
var successMessage = $('.success');
var error = $('.errors-container');
var sharpSpringID = $('#gatewayEmbedID').val();
var submitbtn = $('.button-submit');
var SubmitProgress = $('img.progress');
var formdata = {};
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
submitbtn.click(function (e) {
resetErrors();
postForm();
});
function resetErrors() {
$('.signupForm input').removeClass('error-field');
}
function postForm() {
$.each($('.signupForm input'), function (i, v) {
if (v.type !== 'submit') {
formdata[v.name] = v.value;
}
});
submitbtn.hide();
error.hide();
SubmitProgress.show();
$.ajax({
type: "POST",
data: formdata,
url: '/wp-content/plugins/sharpspring-form/sharpsring-form-submission.php',
dataType: "json"
}).done(function (response) {
submitbtn.show();
SubmitProgress.hide();
if (response.errors) {
error.show();
var errors = response.errors;
errors.forEach(function (error) {
$('input[name="' + error + '"]').addClass('error-field');
})
}
else {
__ss_noform.push(['submit', null, sharpSpringID]);
setCookie('SignupSuccess', 'NewsletterSignup', 3650);
$('#browserHangFormPV')[0].reset();
$('.form-field-content').hide();
successMessage.show();
$('.button-submit').html("Submitted");
}
});
}
});
}(jQuery));
The jQuery code that sets up the form sliding animation and popup feature, as well as checks for the existence of the JS cookie created on successful form submit:
jQuery.noConflict();
(function ($) {
$(document).ready(function () {
//This function checks if we are in mobile view or not to determine the
//UI behavior of the form.
checkCookie();
window.onload = checkWindowSize();
var arrowicon = $(".arrow");
var overlay = $("#overlay");
var slidingDiv = $(".slider");
var closeBtn = $(".closeBtn");
var mobileBtn = $(".mobile-btn");
//When the page loads, check the screen size.
//If the screen size is less than 768px, you want to get the function
//that opens the form as a popup in the center of the screen
//Otherwise, you want it to be a slide-out animation from the right side
function checkWindowSize() {
if ($(window).width() <= 768) {
//get function to open form at center of screen
if(sessionStorage["PopupShown"] != 'yes' && !checkCookie()){
setTimeout(formModal, 5000);
function formModal() {
slidingDiv.addClass("showForm")
overlay.addClass("showOverlay");
overlay.removeClass('hideOverlay');
mobileBtn.addClass("hideBtn");
}
}
}
else {
//when we aren't in mobile view, let's just have the form slide out from the right
if(sessionStorage["PopupShown"] != 'yes' && !checkCookie()){
setTimeout(slideOut, 5000);
function slideOut() {
slidingDiv.animate({'right': '-20px'}).addClass('open');
arrowicon.addClass("glyphicon-arrow-right");
arrowicon.removeClass("glyphicon-arrow-left");
overlay.addClass("showOverlay");
overlay.removeClass("hideOverlay");
}
}
}
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user = getCookie("SignupSuccess");
if (user != "") {
return true;
} else {
return false;
}
}
/*
------------------------------------------------------------
Functions to open/close form like a modal in center of screen in mobile view
------------------------------------------------------------
*/
mobileBtn.click(function () {
slidingDiv.addClass("showForm");
slidingDiv.removeClass("hideForm");
overlay.addClass("showOverlay");
overlay.removeClass('hideOverlay');
mobileBtn.addClass("hideBtn");
});
closeBtn.click(function () {
slidingDiv.addClass("hideForm");
slidingDiv.removeClass("showForm");
overlay.removeClass("showOverlay");
overlay.addClass("hideOverlay")
mobileBtn.removeClass("hideBtn");
sessionStorage["PopupShown"] = 'yes'; //Save in the sessionStorage if the modal has been shown
});
/*
------------------------------------------------------------
Function to slide the sidebar form out/in
------------------------------------------------------------
*/
arrowicon.click(function () {
if (slidingDiv.hasClass('open')) {
slidingDiv.animate({'right': '-390px'}, 200).removeClass('open');
arrowicon.addClass("glyphicon-arrow-left");
arrowicon.removeClass("glyphicon-arrow-right");
overlay.removeClass("showOverlay");
overlay.addClass("hideOverlay");
sessionStorage["PopupShown"] = 'yes'; //Save in the sessionStorage if the modal has been shown
} else {
slidingDiv.animate({'right': '-20px'}, 200).addClass('open');
arrowicon.addClass("glyphicon-arrow-right");
arrowicon.removeClass("glyphicon-arrow-left");
overlay.addClass("showOverlay");
overlay.removeClass("hideOverlay");
}
});
});
}(jQuery));
I'm confused by the WordPress code here, rather than SilverStripe, it's not clear in your question which platform you're using.
Basically, if you want something more robust than cookies, you'll need to store the registration in the database and check it there (assuming the registration form is on your site). This means you handle the form submission on your site, send the data to the remote site and check the responses, and if all goes well, save the fact that the user has registered remotely into your database where you can check when deciding whether to show the form or not, next time.
If you don't have access to the registration form, or you want to also notice registrations made independently of your site, then you need to have an API you can query on the remote site in order to see if the user is registered.
I found a sharpspring API, but I'm not sure if it's relevant.

Use code captcha in two forms

I have two forms on a page containing Google captcha code, but only one code works. Does anyone know if you can use the same code with the same key on two forms on the same page?,
Thks,
Yes, you can. But you have to explicitly render the widget as mentioned on the developer guide
you should use something like this on your front end(taken from the developer guide):
<html>
<head>
<title>reCAPTCHA demo: Explicit render for multiple widgets</title>
<script type="text/javascript">
var verifyCallback = function(response) {
alert(response);
};
var widgetId1;
var widgetId2;
var onloadCallback = function() {
// Renders the HTML element with id 'example1' as a reCAPTCHA widget.
// The id of the reCAPTCHA widget is assigned to 'widgetId1'.
widgetId1 = grecaptcha.render('example1', {
'sitekey' : 'your_site_key',
'theme' : 'light'
});
widgetId2 = grecaptcha.render(document.getElementById('example2'), {
'sitekey' : 'your_site_key'
});
grecaptcha.render('example3', {
'sitekey' : 'your_site_key',
'callback' : verifyCallback,
'theme' : 'dark'
});
};
</script>
</head>
<body>
<!-- The g-recaptcha-response string displays in an alert message upon submit. -->
<form action="javascript:alert(grecaptcha.getResponse(widgetId1));">
<div id="example1"></div>
<br>
<input type="submit" value="getResponse">
</form>
<br>
<!-- Resets reCAPTCHA widgetId2 upon submit. -->
<form action="javascript:grecaptcha.reset(widgetId2);">
<div id="example2"></div>
<br>
<input type="submit" value="reset">
</form>
<br>
<!-- POSTs back to the page's URL upon submit with a g-recaptcha-response POST parameter. -->
<form action="?" method="POST">
<div id="example3"></div>
<br>
<input type="submit" value="Submit">
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer>
</script>
</body>
</html>
I just wanted a HTML snipped which I can insert multiple times, each time displaying another captcha. Also, I did not want to take care for specific IDs assigned to the containers, which would be very annoying when multiple formulars still appearing on one page will be designed and rendered independently. Here is my solution.
<div class="g-recaptcha"></div>
<script type="text/javascript"><![CDATA[
function renderCaptchas() {
var captchaNodes = document.getElementsByClassName('g-recaptcha');
for (var i = 0; i < captchaNodes.length; i++) {
var captchaNode = captchaNodes[i];
if (!captchaNode.captchaRendered) {
captchaNode.captchaRendered = true;
grecaptcha.render(captchaNode, {"sitekey": "YOUR_SITE_KEY"});
}
}
}
]]></script>
<script src="https://www.google.com/recaptcha/api.js?onload=renderCaptchas&render=explicit" async="async" defer="defer"></script>

Facebook "signed_request" using pure Classic ASP

I would like to get the contents of the signed_request in my fb app, but using only Classic ASP with VBScript.
Facebook's site has an example in PHP of decoding this but I can't find anything for ASP.
I think I need to decode the base64url, then read the JSON, but I don't know how.
I was in the same boat you are. All of the sites which provide code to create a gate are written in PHP. Using the code on ChiliPepperDesign's "Reveal / Fan-Gate / Like-Gate Facebook iFrame Tab" as a starting point, I converted the PHP to ASP/VBScript, and found sources for the base64 decode and JSON decode (which PHP apparently does natively).
The JSON.decode script I got from GitHub. Yes, it is Javascript, but you can run it on an ASP/VBScript site if you preface the code on the page with this:
<%#LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<script language="JSCRIPT" runat="server">
Put all of the downloaded Javascript in, and then close with the usual </script> tag. Save this file as json_decode.asp.
The base64 decode was a little harder (the one I initially downloaded sorta worked and sorta did NOT work). I found a better version on Free VBCode. Downlaod that and put it into another file, base64_encode-decode.asp.
Finally, the code to bring it all together is:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<!-- #INCLUDE FILE="json_decode.asp" -->
<%
Dim encoded_sig, payload, sig, data, myArray
Function parsePageSignedRequest()
If Request("signed_request") <> "" THEN
myArray = Split(Request("signed_request"), ".")
encoded_sig = myArray(0)
payload = myArray(1)
sig = base64_decode(Replace(encoded_sig, "-_", "+/"))
set data = JSON.parse(base64_decode(Replace(payload, "-_", "+/")))
parsePageSignedRequest = data
If data.page.liked Then %>
<p>Thank you for liking us!</p>
<% Else %>
<p>Please click the "like" button to continue.</p>
<% End If
Else
parsePageSignedRequest = ""
End If
End Function
'' -- run the function
parsePageSignedRequest()
%>
Save this as facebook-likeGate.asp on your site in the same location as the two include files, and point Facebook to this page.
HTH
JF
Here is the code without the use of json_decode.asp
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<%
Dim encoded_sig, payload, sig, data, myArray
Function parsePageSignedRequest()
If Request("signed_request") <> "" THEN
myArray = Split(Request("signed_request"), ".")
payload = myArray(1)
payload = base64_decode(payload)
If instr(payload,"liked"":true,") Then %>
<p>Thank you for liking us!</p>
<% Else %>
<p>Please click the "like" button to continue.</p>
<% End If
Else
parsePageSignedRequest = ""
End If
End Function
parsePageSignedRequest()
%>
You can use new JS SDK. Here is a sample which I have coded and used. Post method works good.
<head>
<SCRIPT language="JavaScript">
setInterval('SubMe()',1500);
function SubMe()
{
if(document.getElementById('fbmail').value != ''){
document.form.submit();
}
}
</SCRIPT>
</head>
<body>
<div id="fb-root"></div>
<h2></h2><br />
<div id="user-info"></div>
<p><fb:login-button scope="email,publish_stream,user_about_me,user_location,user_birthday" on-login="top.location = '';" autologoutlink="true"></fb:login-button></p>
<script>
window.fbAsyncInit = function() {
FB.init({ appId: 'APP ID',
status: true,
cookie: true,
xfbml: true,
oauth: true});
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse) {
//user is already logged in and connected
var userInfo = document.getElementById('user-info');
FB.api('/me', function(response) {
userInfo.innerHTML='Redirecting...If doesnt work click here';
document.getElementById('fbmail').value = response.email;
document.getElementById('fbid').value = response.id;
document.getElementById('fbname').value = response.name;
document.getElementById('fbbirthday').value = response.birthday;
document.getElementById('fbhometown').value = response.hometown.name;
button.innerHTML = 'Logout';
});
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
button.innerHTML = 'Logout';
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML='Redirecting...If doesnt work click here';
document.getElementById('fbmail').value = response.email;
document.getElementById('fbid').value = response.id;
document.getElementById('fbname').value = response.name;
document.getElementById('fbbirthday').value = response.birthday;
document.getElementById('fbhometown').value = response.hometown.name;
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'email'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<form method="post" name="form" id="form" action="go_little_caeser.asp">
<input name="fbmail" id="fbmail" type="hidden">
<input name="fbid" id="fbid" type="hidden">
<input name="fbname" id="fbname" type="hidden">
<input name="fbbirthday" id="fbbirthday" type="hidden">
<input name="fbhometown" id="fbhometown" type="hidden">
</form>
</body>

My facebook login popup window is not centered, how can I center it?

The following code displays a facebook log in link, and works fine in all respects, execpt that when clicked, the facebook login popup window is not centerned (instead it appears awkwardly at the right middle portion of the screen):
<div class="provider_logo big" name="facebook">
<div class="inner">
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
function check_login_status() {
var FB_API_KEY = "XXXXXXXXXXXXXXX";
FB.init({
appId:FB_API_KEY, cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if (response.session) {
redirect_to_done_page();
} else {
FB.login(function(response) {
if (response.session) {
redirect_to_done_page();
} else {
// user cancelled login
}
}, {perms:'email'});
}
});
}
function redirect_to_done_page() {
window.location = "/account/facebook/done/";
}
</script>
<a style="position: relative; top: -8px;" href="javascript:void(0);" onclick="check_login_status()" perms="email"><img src="/images/facebook.gif" /></a>
I tried sticking the var left, and var top options to the beginning of the script to see if that would position the window but it didn't. Any suggestions on how I can modify the above code to center the popup window that appears?
All answers are appreciated, thanks.
Your facebook div
<div id="fb-root"></div>
is within another. Try to place it right underneath your body tag!

Basic FBJS in an FBML Facebook application

I have tried just about every suggestion known to man to get the basic FBJS working in my FBML app.
Here is my code
<script>
<!--
function areyousure(description,id,opt) {
debugger;
var dialog = new Dialog(Dialog.DIALOG_POP).showChoice('Are you sure?','Are you sure you want to delete "' + description + '"? This action cannot be undone!','Yes','No');
dialog.onconfirm = function() {
document.setLocation("http://apps.facebook.com/myapp/delete.php?rec
ord=" + id + opt);
}
}
//-->
</script>
<a href="#" onclick="areyousure(arg1,arg2,arg3);" >click me</a>
When I click the link, I get a a1234543_areyousure not found.
Help Please.
Thanks
I think you are messing a ";" in a href :
<a href="#" onclick="areyousure(arg1,arg2,arg3);" >click me</a>
The parameters didn't exist. This works:
<script>
<!--
function areyousure() {
var dialog = new Dialog(Dialog.DIALOG_POP)
dialog.showMessage('test','foo');
}
//-->
</script>
<a href="#" onclick="areyousure();" >click me</a>