Clear form with jQuery breaks success message
<p>I've got a simple form where you input an email then submit. The form is sent via jquery to a php script which sends the email (if email is valid) returns a JSON response and then the jquery shows a success or failure message in a div based on the response. Got all that working.</p>

<p>What I want to do is clear the form if it is validated as a successful send. I can clear the form field and show the success/failure message with no problem, but found one bug. If someone inputs another email into the form, then the success (or fail) message doesn't appear. However, the php is still executing the data (sending the email) correctly. Only the success/fail message is missing. The success/fail message works the first time you submit the form, but after reset it doesn't. Here is the form:</p>

<pre><code>&lt;form action="" id="emailsend" method="post" &gt;
Email: &lt;input type="text" name="email" /&gt;&lt;br /&gt;
&lt;input type="submit" name="submit" value="Submit" ; /&gt;
&lt;/form&gt;
</code></pre>

<p>Div where success/fail message appears:</p>

<pre><code>&lt;div id="formResponse"&gt;&lt;/div&gt; 
</code></pre>

<p>jquery</p>

<pre><code>$(document).ready(function(){  

$("#emailsend").submit(function(){  

    $.ajax({  
        type: "POST",  
        url: "sendunit4.php",  
        data: $("#emailsend").serialize(),  
        dataType: "json",  

        success: function(msg){  
            $("#formResponse").removeClass('error');  
            $("#formResponse").removeClass('success');  
            $("#formResponse").addClass(msg.status);  
            $("#formResponse").html(msg.message);
            $('#formResponse').fadeOut(2000);
            $('#emailsend')[0].reset();



        },  
        error: function(){  
            $("#formResponse").removeClass('success');  
            $("#formResponse").addClass('error');  
            $("#formResponse").html("There was an error submitting the form. Please try again.");  
        }  
    });  

    return false;  

});  

});  
</code></pre>

<p>Relavent part of PHP script (sendunit4.php):</p>

<pre><code>$to = $_POST['email'];
if ($recipients = $swift-&gt;send($message, $failures))
{
$response_array['status'] = 'success';  
$response_array['message'] = 'Email sent!';
}
else{
$response_array['status'] = 'error';  
$response_array['message'] = 'There was a problem sending';  
}
echo json_encode($response_array); 
</code></pre>

<p>Any ideas would be appreciated. Thanks!</p>
