Conflict between Featherlight.js and Contact Form 7? - contact-form-7

I'm trying to get a Contact Form 7 form to work in a Featherlight.js lightbox. I've created a page at mydomain.com/contact and set the link to open mydomain.com/contact #main article.
Featherlight does open the form, but when I submit the form, the lightbox closes and the url resolves to mydomain.com/contact/#wpcf7-f262-p11-o1. It doesn't matter if it's successfully submitted or there are validation errors, the lightbox still closes (to be clear, the form does actually work—I receive the email).
If I open the entire page (mydomain.com/contact/), the lightbox doesn't close on submission, which leads me to believe that perhaps there's an AJAX conflict.
That said, I don't receive any errors in the console.
Any help in resolving the issue would be appreciated!
Thanks.

I've got it working, thanks to the second part of the accepted answer here (the Documentation example from the jQuery website).
jQuery's submit() function didn't work for me—I'm guessing it's a version issue? In any case, this is my final code:
/* attach a submit handler to the form */
$( "body" ).on( "submit", ".wpcf7-form", function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
url = $form.attr( 'action' );
/* Send the data using post */
var posting = $.post( url, $form.serialize() );
/* Put the results in a div */
posting.done(function(data) {
var content = $(data).find('.wpcf7-form');
$('.featherlight .wpcf7').empty().append(content);
});
});

Related

Causing an Angular form to POST

When a form is valid, I want it to POST the value to a web site.
I get the alert to fire nicely when the form is not valid, but I can't set the action and cause the form to submit when the form is valid.
So, the result should be that the form posts and the browser goes to the next page like a traditional html form.
<form name="userForm" ng-submit="submitForm(userForm)" novalidate>
......
validationApp.controller('mainController', function($scope) {
// function to submit the form after all validation has occurred
$scope.submitForm = function(form) {
if(form.$invalid){
alert("form invalid");
}
else
{
form.action="http://microsoft.com";
form.submit();
}
};
});
Angular doesn't works that way. Angular mostly expects a RESTful web service to answer its calls. Yes, you can get it working with action somehow. However, for redirecting you would have to make use of $location web service. Through $location you can redirect your page to next page.
$scope.submitForm=function(form){
if(form.$invalid){
alert("form invalid");
}
else
{
$http.post(url:'yourURL', yourData));
$location.path='newURL';
}
From the documentation on ngSubmit:
Additionally it prevents the default action (which for form means sending the request to the server and reloading the current page), but only if the form does not contain action, data-action, or x-action attributes.
Otherwise, I think you can pass $event to the function and trigger $event.srcElement.submit(). The object you're passing to the function isn't the form element itself, which is why it won't submit. If you want, you can pass both by doing ng-submit="submitForm($event, userForm)". Hope that helps!

Open ColorBox with link generated by hashchange event

Our company wants to include a LinkedIn Share Button in the news section of our website. It is relatively simple and consists of a carousel that open up the news items individually in Colorbox windows. We want the LinkedIn button to be within the Colorbox windows so that we can share the details of each news item.
So, I have successfully got the hashchange event to work when Colorbox is activated in order to show the correct url for each news item and the LinkedIn button does return the correct url when the news item is shared, however Colorbox doesn't open, it simply links to the index page of our site. My question is how do I fire up Colorbox from this shared link?
I have researched a lot of similar questions but cannot seem to get it working. Any help would be much appreciated. Thank you.
Below is my js and also a jsfiddle: http://jsfiddle.net/stegern/WvfsA/11/
$(document).ready(function()
{
//Carousel for news items
$('#news-carousel').show();
$('#news-carousel').jcarousel({
vertical:true,
scroll:true,
wrap:'circular'
}
);
$('.popup').colorbox({
title: function()
{
var url = $(this).attr('href');
return '#' + url;
},
onOpen:function()
{
window.location.hash = $(this).attr('href');
},
onClosed:function()
{
window.location.hash = "";
},
opacity: 0.7,
transition: 'fade'
}
);
//Attempt to open ColorBox when url is shared
$(function(){
var hash = window.location.hash;
if ('onhashchange' in window)
{
window.onhashchange = hashChanged;
}
else
{
setInterval(function(){
if (window.location.hash != hash)
{
hash = window.location.hash;
hashChanged();
}
}, 500);
}
var hashChanged = function(){
$.colorbox();
}
}
);
});
UPDATE
I have done some more research and discovered that I need to load my content in an iframe rather than using Ajax. I then need to add a querystring to my news item links and parse the parameters from the querystring in order to pass them to ColorBox.
However I am now getting a semantic issue with my js (line 8 Expected ')' token) which I don't know how to resolve. Can someone please explain.
Here is my html markup:
<ul>
<li>News Item One
</li>
<li>News Item Two
</li>
<li>News Item Three
</li>
And here is my js:
function getParameters() {
var
settingsObject = {},
hash,
hashes = location.search.substring(1).split(/&/),
i;
for (i = 0; i & lt; hashes.length; i++) {
hash = hashes[i].split('=');
settingsObject[hash[0]] = hash[1];
}
return settingsObject;
}
$('a.cb').colorbox($.extend({
iframe: true,
width: '800',
height: '600'
}, getParameters()));
I also have a jsfiddle setup at: http://jsfiddle.net/stegern/NtSvg/7/
Try putting some example code in a fiddle at http://jsfiddle.net/ then share here.
You posted your js, but we don't have the markup you're trying to use it on, so post the minimum necessary html code to make your example work in a fiddle.
It will help others visualize your problem much easier and quite possibly get you a solution a lot faster.
Ajax isn't loading because browsers typically disallow cross-origin file access for security reasons.Since the main code is hosted on jsfiddle, it forbids you to load pages from your site via ajax.
A quick workaround, if you're using Chrome, you can start it in a less secure mode, like indicated here: https://superuser.com/questions/593726/is-it-possible-to-run-chrome-with-and-without-web-security-at-the-same-time
I just tested now by opening a command prompt in the folder where chrome.exe is located and ran chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
Then I opened http://jsfiddle.net/WvfsA/12/ , where I stripped down your js to the minimum. You'll see your content is now loaded via ajax by colorbox, however, you're doing something wrong with those paths, because the images can't be found.
I took a look at http://jsfiddle.net/WvfsA/13/ and I'm not sure exactly why you have 2 nested $(function () {}), I saw that in Framework & Extensions, ondomready is already selected, so you don't really need to wrap your main function(s) in anything.
Here's a quick screenshot as proof that it works:
http://i.imgur.com/jAiUW28.png?1
When you were developing, were you running your example through a server? You need to have a local server in order for anything ajax-related to work.
Install XAMPP http://www.apachefriends.org/en/xampp.html if you haven't already?
Edit: or you could develop on Chrome launched with that flag I mentioned, to bypass the need of a local webserver, but it's not a really good idea.

jquery.form.js is not working in Internet Explorer 9

I have a simple form with a file upload control. The form will be posted once I click on the upload button. I'm trying to do a jquery-ajax post, using the jquery.form.js.
My code is as follows,
var options = {
beforeSubmit: function (formData, jqForm, options) {
$(".loaderImage").show();
return true;
},
success: function (responseText, statusText, xhr, $form) {
$("#result").html(responseText);
},
error: function(xhr) { alert(xhr.responseText); }
};
$("#AjaxFileUpload").ajaxSubmit(options);
return false;
It works fine in Google Chrome, Firefox and Internet Explorer 10. The problem with Internet Explorer 9 is, after debugging, it doesn't enter the success(). Any pointers on what's going wrong? There are no errors in the console either.
I added the error option as well, but the issue is the same, the breakpoint doesn't hit the alert.
I just had a look at the network traffic. There is no POST request going (in Internet Explorer 9) when I click the upload button, but there's a POST request going in Internet Explorer 10.
I cleared the cache and reset browser settings as well. But the issue persists.
badZoke, I was experiencing this same problem yesterday and most of today and finally figured out what was causing it (in my case). This might be helpful for your situation, as well:
Internet Explorer has restrictions about form submission when the form is not currently in the DOM. In my case, a user interacted with a button in a modal popup (which also contained the form). When they clicked, the form was removed from the DOM (but still accessible via a js var) and replaced with a loading bar. I then called myForm.ajaxSubmit(options); which in IE<10 attempts a submission of that form to a temporary <iframe/>. Not allowed unless the form is in the DOM.
If your code above was a simplification of your actual scenario and you were doing something similar to me, this may be your problem. Best of luck.
The first step would be to see if the error callback is invoked:
var options = {
beforeSubmit: function (formData, jqForm, options) {
$(".loaderImage").show();
return true;
},
success: function (responseText, statusText, xhr, $form) {
$("#result").html(responseText);
},
error: function(xhr) { alert(xhr.responseText); }
};
$("#AjaxFileUpload").ajaxSubmit(options);
Your code is working fine on my computer, and I'm using Internet Explorer 9. Maybe the problem is not here.

Facebook PHP SDK Capture Like Event

I need to record to the database if a user likes an iframe page tab using the official Facebook 'like' button at the top. I did a search here at stackoverflow and found a javascript snippet ...
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
But it doesn't fire for the official button (only like buttons added to the page)? I declare it after FB.init and before FB.Canvas resize inside the asynchronous call. Is there a way in PHP to capture this - possible on refresh? Either JS or PHP is okay (since JS can simply ajax a php file). The signed request contains whether they like the page or not but I need to capture it as it happens (or just happened).
Any help greatly appreciated :-)
Try :
window.fbAsyncInit = function () {
FB.Event.subscribe('edge.create', function (targetUrl) {
_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
});
};
I think you just need to setup the subscript inside the fbAsyncInit.
Did it a purely PHP way in the end.
1: Get the signed request from facebook and extract the liked stats
2: Create a variable $liked and set to "yes" or "no" based on signed request value
3: Manipulate a session - use a session because the page gets refreshed when you "like" but the session remains (but the request value will have changed)
if(isset($_SESSION['likestatus'])){
if($_SESSION['likestatus'] == "no" && $liked == "yes"){
// do mysql updatestuff cause has liked page since session started
$_SESSION['likestatus'] = $liked;
}
else{
$_SESSION['likestatus'] = $liked;
}
}
else {
$_SESSION['likestatus'] = $liked;
}

Facebook Register Plugin - Form submitting even though validation fails?

I'm using the Facebook Registration Plugin (http://developers.facebook.com/docs/plugins/registration/) to register users for our site. The problem is I can't seem to get custom validation working and was wondering whether it's a mistake on my part or something wrong with Facebook.
This is the XFBML code that I'm using:
<fb:registration
fields="[{'name':'name'},
{'name':'email'},
{'name':'password','description':'Enter a password','type':'text'}]"
redirect-uri="http://local.dev"
onvalidate="validateFacebookRegistrationForm">
</fb:registration>
and I have a global function called validateFacebookRegistrationForm which has the following code in it:
function validateFacebookRegistrationForm(form) {
errors = {};
if (form.password == "") {
errors.password = "No Password Entered";
}
return errors;
}
I would expect hitting the register button on the form would do nothing and the validation message would show up... instead I get a popup like this:
http://i.imgur.com/ERxw3.jpg
Once the popup is closed, the form is validated ... and the error message shows. Clicking register again will not submit the form until the errors have been fixed - which is the how the form should behave in the first instance!
The Facebook Registration plugin does not client-side validate until AFTER the user has pressed "Register" and then in the popup pressed "Continue". Then, it will do the "client-side" validation... it really doesn't make sense to go in that order but that's how it seems to be.
Your code is fine.