Form Auto-Submit with if-else to check for anonymous
1 Votes
Discussion thread from previous developer forum:
Form Auto-Submit with if-else to check for anonymous
In the A/O Knowledge Base, there is a jQuery snippet that you can add to a Form to automatically submit the form.
Basically, the system will ID the visitor, populate the form and submit so the user only has to click one button and it's done.
Beautiful!
You can find it here:
https://support.actonsoftware.com/hc/en-us/articles/204679440-Using-a-Code-Snippet-to-Auto-submit-a-Form
It's great to use with an A/O email, but what about Landing Pages?
If you end up with anonymous visitors to a Landing Page, the form submits but it is empty.
So, I noodled around with that code snippet to make it an if/else statement.
** IF email form field is empty, then redirect to the form.
ELSE auto-submit. **
My variation looks like this (in this case redirecting to google instead of an A/O form).
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script>
jQuery.noConflict();
jQuery(document).ready(function ( $ ) {
if ($('#E-mail').val() == '' ) {
window.location.href = 'http://google.com'
} else {
$('input[name='Submit']').click();
}
});
</script>
I've tried the 'IF' statement a couple different ways to no avail.
It seems my results are that everyone gets redirected or every form gets auto-submitted, some filled in, some blank.
Any suggestions how to finalize this??
Thanks! Regards.
REPLY #1
Cool. Would it be acceptable, then, to simply redirect persons who are visiting the landing page that are Anonymous to Act-On? My thinking is that we can use a function that defines a isAnonymous() function (which returns true or false based on the visitor being anonymous or not). Then, if isAnonymous() == true, your redirect function can come in.
Here's the script that would do that. You can see the redirect portion is at the very bottom.
<script>
var getCookie = function (name)
{
var dc = document.cookie;
var prefix = name + '=';
var begin = dc.indexOf('; ' + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(';', begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
};
var isAnonymous = function() {
var c = getCookie('wp24998');
return !c || c.length < 7 || c.substr( 5, 2 ) == 'DD';
};
if(isAnonymous() == true){
window.location.href = 'https://google.com';
}
</script>
REPLY #2
So to clarify:
If Email field value == ' ' or null --> redirect to form
Else if Email field has a non-null value --> auto submit the form?
I noticed you are saying though that this would occur on a landing page. Is there a second, preliminary form on the LP that is being referenced to distinguish known vs. unknown?
REPLY #3
Thanks!
Yes, you got it.
IF/ELSE
IF the system recognizes the user, populate the form for them and Auto-Submit
ELSE if the user is anonymouse, redirect to another form (I just used the redirect to the google URL in the code I posted for simplicity)
There is actually not a form on the LP at all.
There is a link to a form.
That form includes the Auto-Submit script (that I want to expand to an IF/ELSE script)
So, I guess at that point, if the user is not recognized by the system, the form (script) would redirect to another form in the system.
Form Auto-Submit with if-else to check for anonymous
In the A/O Knowledge Base, there is a jQuery snippet that you can add to a Form to automatically submit the form.
Basically, the system will ID the visitor, populate the form and submit so the user only has to click one button and it's done.
Beautiful!
You can find it here:
https://support.actonsoftware.com/hc/en-us/articles/204679440-Using-a-Code-Snippet-to-Auto-submit-a-Form
It's great to use with an A/O email, but what about Landing Pages?
If you end up with anonymous visitors to a Landing Page, the form submits but it is empty.
So, I noodled around with that code snippet to make it an if/else statement.
** IF email form field is empty, then redirect to the form.
ELSE auto-submit. **
My variation looks like this (in this case redirecting to google instead of an A/O form).
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script>
jQuery.noConflict();
jQuery(document).ready(function ( $ ) {
if ($('#E-mail').val() == '' ) {
window.location.href = 'http://google.com'
} else {
$('input[name='Submit']').click();
}
});
</script>
I've tried the 'IF' statement a couple different ways to no avail.
It seems my results are that everyone gets redirected or every form gets auto-submitted, some filled in, some blank.
Any suggestions how to finalize this??
Thanks! Regards.
REPLY #1
Cool. Would it be acceptable, then, to simply redirect persons who are visiting the landing page that are Anonymous to Act-On? My thinking is that we can use a function that defines a isAnonymous() function (which returns true or false based on the visitor being anonymous or not). Then, if isAnonymous() == true, your redirect function can come in.
Here's the script that would do that. You can see the redirect portion is at the very bottom.
<script>
var getCookie = function (name)
{
var dc = document.cookie;
var prefix = name + '=';
var begin = dc.indexOf('; ' + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(';', begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
};
var isAnonymous = function() {
var c = getCookie('wp24998');
return !c || c.length < 7 || c.substr( 5, 2 ) == 'DD';
};
if(isAnonymous() == true){
window.location.href = 'https://google.com';
}
</script>
REPLY #2
So to clarify:
If Email field value == ' ' or null --> redirect to form
Else if Email field has a non-null value --> auto submit the form?
I noticed you are saying though that this would occur on a landing page. Is there a second, preliminary form on the LP that is being referenced to distinguish known vs. unknown?
REPLY #3
Thanks!
Yes, you got it.
IF/ELSE
IF the system recognizes the user, populate the form for them and Auto-Submit
ELSE if the user is anonymouse, redirect to another form (I just used the redirect to the google URL in the code I posted for simplicity)
There is actually not a form on the LP at all.
There is a link to a form.
That form includes the Auto-Submit script (that I want to expand to an IF/ELSE script)
So, I guess at that point, if the user is not recognized by the system, the form (script) would redirect to another form in the system.
Please sign in to leave a comment.
Comments
0 comments