Halt progress of Ninja Forms if Webhooks respond with error - wordpress

I'm setting up Ninja Forms in Wordpress. And I want to use the Webhooks extension to post a code to an external URL. If the code is correct Ninja Forms should submit the data on move on. If the code is wrong then the user should get an error message and try again.
How can I do this, I see no way if interrupting the submit?

In Ninja Form when you use webhook, I guess you may catch the error respond from the API with this code
$data['errors']['form'][] = $this->submit_response->result[0]->error;
So when the API respond error, in this case user has no chance to re-submit the form again unless reload the page.
When the form contain the error, Ninja form prevent the form to submit, so you need to find a way to clear/remove this error.
Few workarounds can fix this problem.
An easy way is that, you cache the respond error differently with the following code:
$data['errors']['last']['message'] = $this->submit_response->result[0]->error;
With this code, your form will not display the error message respond from API but it is possible for user to re-submit the form again and you can use the javascript code below to display the error to some HTML element
var customFormController = Marionette.Object.extend({
initialize: function() {
// Listen to submit respond
this.listenTo(nfRadio.channel( 'forms' ), 'submit:response', this.checkSubmitRespond);
},
checkSubmitRespond: function(response, textStatus, jqXHR, formID) {
if ('undefined' != typeof response.errors.last) {
var msg = response.errors.last.message;
// display error on some pre-defined element
jQuery('.error-container').html(msg);
}
}
});
jQuery(document).ready(function($) {
new customFormController();
});
Hope this help.

Related

session email become undefined when i reload page in meteor JS

i store email using session .set('email','email name') but when i reload page that time this session email is become undefined. i use Session.get('email') to get user email.
Router.route('profile', {
path: '/profile',
data: function() {
$("body").removeClass('home');
this.render('profile');
setTimeout(function(){
$('#username').html(Session.get('first_name'));
$('#profile_username').html(Session.get('first_name'));
$('#setting_name').val(Session.get('first_name'));
$('#setting_username').val(Session.get('first_name'));
$('#setting_email').val(Session.get('email'));
$('#user_id').val(Session.get('id'));
$('.setting_day').val(Session.get('day'));
$('.setting_month').val(Session.get('month'));
$('.setting_year').val(Session.get('year'));
if(Session.get('image')!= ''){
$('.user_profile_image').attr("src",Session.get('image'));
}
if(Session.get('gender') == 0){
$('#user_gender').html('Male');
}else{
$('#user_gender').html('Female');
}
$('#day').html(Session.get('day'));
$('#month').html(Session.get('month'));
$('#year').html(Session.get('year'));
},100);
},
onBeforeAction: function () {
alert(Session.get('email'));
if(Session.get('email')){
this.next();
}else {
this.redirect('/');
}
}
});
install persistent package Session. Your session variables will persist across routes also. You need to configure it via Meteor settings. so don't forget include the settings when you run project.
u2622:persistent-session
When you reload the page page in meteor all the client side reactive things reinitialize So if you want to keep the email when page refresh then you have to send it on the server and then you can fetch this when according to your need. You can save it into a collection and then fetch from a meteor call or publish-subscribe according to your need.
When you refresh the page you are no longer in the same session so what you describe is the expected and correct default behavior. There is a package (I don't know it's name right now, but should be easy to find on atmospherejs) which gives you Session.setPersistent(...). I think this is what you are looking for.

Meteor: Resend email verification link

I want to be able to resend an email verification link to users of my Meteor application in case they accidentally delete their email verification email.
I have a link with the id "resentEmailVerificationLink"
I have the following code in my client for when the link is click (alerts are just there to show myself how far the function gets before an error):
Template.dashboard.events({
'click #resentEmailVerificationLink' : function(event) {
event.preventDefault();
var id = Meteor.userId();
alert('clicked: ' + id);
Accounts.sendVerificationEmail(id);
alert('Verification Email resent');
return false; // Stops page from reloading
}
)};
I know the sendVerificationEmail is a server function but I have no idea how to call this function in the server upon clicking the verify email link (I'm a bit of a Meteor newbie).
Any idea of how to accomplish this, because currently it doesn't work with the following error: Uncaught TypeError: Accounts.sendVerificationEmail is not a function
Note: Meteor.Accounts.sendVerificationEmail(id); doesn't work either (it does however produce a different error.
You can try with server side method just create one pass the attrs and call http://docs.meteor.com/#/full/accounts_sendverificationemail on the server. More about meteor methods: http://docs.meteor.com/#/full/meteor_methods

Meteor Streams : client doesn't receive streams

i'm working on a simple app based on meteor and MeteorStreams.
The aim is simple :
one user will click on a button to create a room
other users will join the room
those users can emit streams with simple message
the creator will listen to that message and then display them
In fact : message from other users are sent (log in server script), but the creator doesn't receive them.
If i reload the page of the creator, then it will get messages sent from other user.
I don't really understand why it doesn't work the first time.
I use meteor-router for my routing system.
Code can be seen here
https://github.com/Rebolon/MeetingTimeCost/tree/feature/pokerVoteProtection
for the client side code is availabel in client/views/poker/* and client/helpers
for the server stream's code is in server/pokerStreams.js
Application can be tested here : http://meetingtimecost.meteor.com
The creator must be logged.
If you have any idea, any help is welcome.
Thanks
Ok, Ok,
after doing some debugging, i now understand what is wrong in my code :
it's easy in fact. The problem comes from the fact that i forgot to bind the Stream.on event to Deps.autorun.
The result is that this part of code was not managed by reactivity so it was never re-run automatically when the Session changed.
The solution is so easy with Meteor : just wrap this part of code inside the Deps.autorun
Meteor.startup(function () {
Deps.autorun(function funcReloadStreamListeningOnNewRoom () {
PokerStream.on(Session.get('currentRoom') + ':currentRoom:vote', function (vote) {
var voteFound = 0;
// update is now allowed
if (Session.get('pokerVoteStatus') === 'voting') {
voteFound = Vote.find({subscriptionId: this.subscriptionId});
if (!voteFound.count()) {
Vote.insert({value: vote, userId: this.userId, subscriptionId: this.subscriptionId});
} else {
Vote.update({_id: voteFound._id}, {$set: {value: vote}});
}
}
});
});
});
So it was not a Meteor Streams problem, but only my fault.
Hope it will help people to understand that outside Template and Collection, you need to wrap your code inside Deps if you want reactivity.

jQuery - Ajax showing empty RESPONSE / Success: not triggered when used with WordPress posts and pages

Any help would be appreciated.
I have created a small script which works fine when used with simple php pages. Now I just tried to add this script to my WordPress posts and pages. So I used "exec-php" plugin to call the php script.
Everything works fine. But when user fills the data and submits the form, the data actually gets submitted (I can see the posted variables in firebug), but the response is not displayed under the form when used with wordpress, where as it works fine when used with plain php pages.
My jQuery code is like this:
var dataString = 'name=' + name + '&country=' + country + '&lang=' + language;
$("#paypal-submit").click(function () {
$.ajax({
type: "POST",
url: "get.php",
data: dataString,
dataType: 'html',
success: function (gotresponse) {
$('#response-id').html("<div id='id-message'><p>Got Response</p></div>");
$('#id-message').html(gotresponse).fadeIn(1500, function () {
$('#id-message');
});
$('#name').attr('onchange', 'resetForm()');
$('#country').attr('onchange', 'resetForm()');
}
});
});
When I actually view the whole process in firebug, I can see that the data is actually posted to the server.
200 OK 2.03s
But when I see the response tab in firebug console, it is empty. I think the success message is not getting triggered when used with WordPress.
I cant figure out what could be the problem? Can someone help me solve this?
NOTE: The same script works fine when used as it is, but when used with WordPress the jQuery - Ajax success does not get triggered.
1st Edit:
I just included the error: in ajax function
error:function(x,e){
if(x.status==0){
alert('You are offline!!\n Please Check Your Network.');
}else if(x.status==404){
alert('Requested URL not found.');
}else if(x.status==500){
alert('Internel Server Error.');
}else if(e=='parsererror'){
alert('Error.\nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('Request Time out.');
}else {
alert('Unknow Error.\n'+x.responseText);
}
}
Now when I submit the form I get the alert saing "You are offline!! Please Check Your Network." This error is getting triggered. So please help me now.
On you success:function() , it should success:function(data) then change .html(gotresponse) to .html(data)

FB.ui() giving error in Safari with asynchronous request when user is not already logged in

I'm trying to get have users be able to post to their Facebook walls on my external site.
I've encountered a problem in Safari. If the user isn't logged in, i.e. they have not gone through the flow that calls FB.login(), I get the following JS error when calling FB.ui():
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
However, if they are logged in, the dialog appears just fine.
FB.ui() is called in a callback function -- I'm retrieving a unique url from my server, and then calling FB.ui(). If I call FB.ui() directly, it works fine, but not when it's asynchronous.
Here's the code:
retrieveUrl(param1, param2, function(result) {
FB.ui({ method: 'feed',
description: 'My Description',
display: 'dialog',
link: result.uniqueUrl,
picture: 'http://foo.com/bar.jpg'
}, function(response) {
if (response && response.post_id) {
//Posted message
} else {
//Not posted message
}
});
});
This works in other browsers, regardless of logged in state or not.
FB.login or FB.ui methods must be called on a user initiated action (click) in Safari for new window/popup/iframe to be rendered by FB.UIServer.
If you try calling these methods on a network callback event it will be blocked and the exception you described will occur:
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
Can you retrieve the unique URL before the user interacts with the page and then present the feed dialog when they click on a button?

Resources