Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

With help of other relevant posts here, I have put together a code which allows the users to send me a list of selected posts via e-mail and it is working fine.

Now, I would like a confirmation text eg. 'THANK YOU' appear to the user, once user has clicked the "send email" button. This could appear below the submit button and could have a class so that I could make it a bit pretty using css. I hope this can be achieved with appropriate changes in my codes. Please suggest a correction.

UPDATED : Now my javascript looks like this :

    <script type="text/javascript">
jQuery(document).ready(function($) {
    $('#sendEmail').click(function(){
             $.ajax({
                 type: 'POST',
                 url: 'http://xxxxxxxxxxxxxxx/email.php',
                 data: { content: $('#email-data').html()},
                 success:function(data) {
                        alert('You data has been successfully e-mailed');
                }        
           });
     });
});
</script>

and my HTML looks like this :

<div id="email-data">
    <div id="content">
        some php generated content
    </div>
</div>
<a id="sendEmail"> SEND EMAIL</a>

my email.php looks like this

<?php

  $to = "someone@somemail.com";
  $subject = "FROM WEBSITE";
  $message = $_POST['content'];
  $headers = "From: company <someotherguy@somecompany.in>" . "\r\n" .
             "Content-type: text/html" . "\r\n";
  mail($to, $subject, $message, $headers);
?>

Please let me know if I am not clear enough.

share|improve this question
    
anyone up for some help please ! –  gurung Jan 4 '13 at 14:34

1 Answer 1

up vote 1 down vote accepted

Simply add a Success callback to your Ajax function:

     $('#sendEmail').click(function(){
             $.ajax({
                 type: 'POST',
                 url: 'www.example.com/email.php',
                 data: { content: $('#email-data').html()},
                 success:  function(data) {
                 //data variable can be used if your ajax call returns something
                     do_stuff_here();
                 }
             });
          });

In your case, you could do something like

success:  function() {
    $('body').append('<div class="success">Success!</div>');
}

However, is there a reason you don't want to use a and the .submit() method? (http://api.jquery.com/submit/)

Also, don't forget to validate :)

share|improve this answer
    
Thanks for your time. You put me in the right direction and the job is done. Thank You. –  gurung Jan 4 '13 at 21:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.