roScripts forum

Wordpress Script Generator
Easily write your own wordpress plugins!
www.wpsecrets.com

Learn Simple PHP
Learn PHP with these simple videos!
www.simplephp.com

PLR Poster
Post hundreds of articles to your wordpress blog(s) at a time!
www.softwarefactoryinc.com/blog-software


Go Back   roScripts forum > General > roScripts related discussions

roScripts related discussions If there's anything that you hate, love or wish seing please say it here.

Reply
 
Thread Tools Display Modes
Old 11-10-2007, 07:06 AM   #1 (permalink)
Doc
Junior Member
 
Join Date: Nov 2007
Posts: 2
Rep Power: 0 Doc is on a distinguished road
Default AJAX Contact Form do this on ERROR and that on SUCCESS

Hello, first i'd like to say thank you for this nice little script! It's exactly what i've been looking for. I have a small problem though that i'm not able to resolve. Would it be possible to have either the input fields cleared automatically after the email has been sent or just disable the submit button after a successful submit?

I've managed to disable the button after the first click but if not all of the fields are correctly filled in and the end-user receives an error message they would have to refresh the page and try again.

I ask because I found that an individual could keep hitting the submit button and it'll keep sending the email over and over again. I appreciate your thoughts.
Doc is offline   Reply With Quote
Sponsored Ads   #1.5
Sponsored posting
 
 
Join Date: The beginning
Posts: lots
Sponsored by...

WM Media - Sell Your Website at above market prices!
Adbot is online  
Old 11-10-2007, 12:49 PM   #2 (permalink)
roScripts
Administrator
 
roScripts's Avatar
 
Join Date: May 2007
Location: Bucharest
Posts: 649
Rep Power: 10 roScripts is on a distinguished road
Default Re: AJAX Contact Form

Hi Doc, what you want has been asked before and it's about time to make a sticky. I'll make it like a small tutorial for everyone to understand.

In order for our script to know when it's dealing with an error or success message we will have to modify the javascript code from index.php and make it evaluate the response that is sent back by send.php which will be also a little modified. The responses will now contain a message for our script and a message for the visitor, both of them at the same time. We will split them by a character that we want (I've used the pipe '|') as follows:

If it's an error:
error|you forgot to do this.....bla bla...the error

If it's an ok message:
ok|message sent

The javascript will take this message, explode it by '|' (the character that we chosed) and evaluate the first reponse from our array which in arrays has the index of 0. If the first element of our array (the status) comes back as 'ok', we can add a code that we want in order to disable the form, redirect or whatever. I've just added an if and else statement. You can play and configure your script to output all kinds of messages for different situations.

JAVASCRIPT
onComplete: function(response) {
        update = response.split('|');
        if(update[0]=="ok"){
                log.removeClass('ajax-loading');
                log.setHTML(update[1]);//OR
                //do whatever you like here, the message was sent, disable forms, redirect etc.
        }
        else {
                log.removeClass('ajax-loading');
                log.setHTML(update[1]);
        }
}
Parsed in 0.009 seconds
Here's how the php code will look in this situation.

PHP
if ( $_POST['first_name'] != '' && $_POST['last_name'] != '' && valid_email ( $_POST['e_mail'] ) == TRUE && strlen ( $_POST['message'] ) > 30 )
    {
        $to = '';
        $headers =     'From: '.$_POST['e_mail'].''. "\r\n" .
                'Reply-To: '.$_POST['e_mail'].'' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
        $subject = "Hello! I'm testing my new ajax email that I got from roscripts.com";
        $message = htmlspecialchars($_POST['message']);

        if ( mail ( $to, $subject, $message, $headers ) )
        {//we show the good guy only in one case and the bad one for the rest.
            echo 'ok|Thank you '.$_POST['first_name'].'. Your message was sent';
        }
        else {
            echo 'ok|Message not sent. Please make sure you\'re not
                running this on localhost and also that you
                are allowed to run mail() function from your webserver'
;
        }
    }
    else {
        echo 'error|Please make sure you filled all the required fields,
        that you entered a valid email and also that your message
        contains more then 30 characters.'
;
    }
Parsed in 0.065 seconds
roScripts is offline   Reply With Quote
Old 11-13-2007, 09:31 AM   #3 (permalink)
Doc
Junior Member
 
Join Date: Nov 2007
Posts: 2
Rep Power: 0 Doc is on a distinguished road
Default Re: AJAX Contact Form do this on ERROR and that on SUCCESS

Beautiful! I really appreciate you taking the time to set up and explain how this can be accomplished. I'm going to play with it this weekend and see what kind of damage I can do.

Thanks again!
Doc is offline   Reply With Quote
Old 12-13-2007, 11:37 PM   #4 (permalink)
superbrain
Junior Member
 
Join Date: Dec 2007
Posts: 2
Rep Power: 0 superbrain is on a distinguished road
Default Re: AJAX Contact Form do this on ERROR and that on SUCCESS

I got everything to work for this script and it works great but I am still having problems with creating a redirect.. Here is the script I have and it is still opening the page within the error div area.. How do I escape into the main function and redirect the entire page?

<script type="text/javascript">
window.addEvent('domready', function(){
$('registerForm').addEvent('submit', function(e) {
new Event(e).stop();
var log = $('log_res').empty().addClass('ajax-loading');
this.send({
update: log,
onComplete: function(response) {
update = response.split('|');
if(update[0]=="ok"){
log.removeClass('ajax-loading');
//log.setHTML(update[1]);//OR
document.window.location = "signup3.php";
} else {
log.removeClass('ajax-loading');
}
}
});
});
});

Any help would be appreciated.. I am sure it is an easy fix, I am just not seing it.

Thanks
superbrain is offline   Reply With Quote
Old 12-14-2007, 01:07 AM   #5 (permalink)
superbrain
Junior Member
 
Join Date: Dec 2007
Posts: 2
Rep Power: 0 superbrain is on a distinguished road
Default Re: AJAX Contact Form do this on ERROR and that on SUCCESS

Should of waited a bit before I posted that last one.. I figured it out.

I didn't read the PHP addition for the ok and error section and that is where it was not working..

Thanks for the script.
superbrain is offline   Reply With Quote
Old 03-02-2008, 10:26 AM   #6 (permalink)
Neoszion
Junior Member
 
Join Date: Feb 2008
Posts: 11
Rep Power: 0 Neoszion is on a distinguished road
Default Re: AJAX Contact Form do this on ERROR and that on SUCCESS

Ok I am being a bit of a newbie, I cannot remove my button on form completion I tried adding the following in my javascript:

any help would most appriciated..

HTML4STRICT
<script type="text/javascript">
         window.addEvent('domready', function(){
             $('myForm').addEvent('submit', function(e) {
 
             new Event(e).stop();
             var log = $('log_res').empty().addClass('ajax-loading');
             this.send({
                 update: log,
                 onComplete: function(response) {
                     update = response.split('|');
                     if(update[0]=="ok"){
                             log.removeClass('ajax-loading');
                             //log.setHTML(update[1]);//OR
document.getElementById('submitter').disabled = true;
                     }
                     else {
                             log.removeClass('ajax-loading');
                             log.setHTML(update[1]);
                     }
             }
             });
             });       
         });
     </script>
Parsed in 0.014 seconds

Last edited by Neoszion : 03-02-2008 at 10:29 AM.
Neoszion is offline   Reply With Quote
Old 06-30-2008, 03:37 PM   #7 (permalink)
yesrightconnet
Junior Member
 
Join Date: Jun 2008
Posts: 9
Rep Power: 0 yesrightconnet is on a distinguished road
Exclamation info

excellent thread!!!
yesrightconnet is offline   Reply With Quote
Old 09-29-2008, 03:25 PM   #8 (permalink)
Lihualee
Junior Member
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0 Lihualee is on a distinguished road
Arrow hi

just my two centsbump
__________________
WoW Power Leveling
Lihualee is offline   Reply With Quote
Old 09-30-2008, 08:01 PM   #9 (permalink)
Lihualee
Junior Member
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0 Lihualee is on a distinguished road
Thumbs down Happy

bump and lurk-------------------------------------------------------------wow power leveling..wow power leveling..Cheap WoW Gold..WoW Gold..World Of Warcraft gold,
__________________
WoW Power Leveling
Lihualee is offline   Reply With Quote
Old 10-01-2008, 08:58 PM   #10 (permalink)
Huoliuhi
Junior Member
 
Join Date: Sep 2008
Posts: 13
Rep Power: 0 Huoliuhi is on a distinguished road
Post hi

just my two centsbump-----------------------------------------Wow Gold Store Welcome you! whether you are looking for Cheap WoW Gold,cheap wow power leveling,ffxi gil,eq2 plat or any other game currency or accounts, We provide Cheap WoW Gold , World of warcraft Power Leveling, Cheap WoW Gold..
__________________
hi WoW Gold
Huoliuhi is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax Contact form error in IE only! Neoszion roScripts related discussions 9 10-30-2008 02:54 AM
Hi, Contact Form AJAX issue. Zipline Ajax 2 01-15-2008 05:46 PM
AJAX Contact Form UTF-8 (multilingual) urbanomad roScripts related discussions 3 12-21-2007 12:54 AM
Ajax form validation kwalker Programming 3 11-16-2007 09:42 PM
ajax validation form rossco roScripts related discussions 4 10-25-2007 06:10 AM



All times are GMT. The time now is 12:21 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.