views:

75

answers:

2

I am working on a php form with some jquery, especially for the error and thank you messages. The jquery part can be viewed here:
http://jsbin.com/ohuya3
A working example of the form is available here:
http://cozyphant-living.com/php/formular4.htm
You have to hit the "Formular senden" button to see the message panel.
I wanted to make the thank you and or error panel make slide out and have the text fade in. The script is accepting my code (because it is still working) but actually I can not see that the text actually fades in. I have seen samples of sliding panels with fading in text. So it seems to be a wrong kind of coding that I did.
Any help is appreciated.

+1  A: 

Use .show() with a duration for the simultaneous slide+fade effect you want, in your case:

$("#formResponse").html(data).show('slow')

You can test out the effect here.


For your code specifically you need to remove margin: 0 auto; from the #formResponse object, resulting in the trouble with the above animation code. Also you can serialize your form in a bit easier-o-maintain way, like this overall:

$("#contact_form").submit(function() {
  var arr = $(this).serializeArray();         //serialize form, based on names
  arr.push({ name: 'senden', value: 'yes' }); //add the senden variable
  $.post('mail.php', arr, function(data) {    //pass that object as your data
    $("#formResponse").hide().html(data).show('slow'); //hide before slide!
  }, 'text');
  return false;
});
Nick Craver
@Nick - It sounds like a clean solution but unfortunately this effect is playing (displaying) crazy in chrome. It is just flying out of the right border then it takes place where it belongs to. You can check my link again if you can try in chrome......
Hardy
@Hardy - Check out the updated answer, your issue currently is `margin: 0 auto;` on the element...but you can make it easier to maintain later by doing the above. Also your `.validate()` method is throwing some errors...the plugin isn't included, the placeholder plugin in a 404 and loaded *before* jQuery (jQuery should always be before plugins), and make sure methods like `.validate()` are inside a `document.ready` handler :)
Nick Craver
@Nich - wow, that was a lot but very appreciated. I know, the markup as it is right now is a mess. This is not as I normally do but in that case I was just trying out many different new things and it got a bit messy. Sorry for that. I understand, if I expect some help from this community that I got to keep it clean. I will try your solution next. It seems very different because it is using an array. Let see what comes out. Will tell you soon.
Hardy
@Nick - So I cleaned a little bit the mess and the margin issue, which helped and I used your code snippet but now the form is telling me that my email adress is using a wrong format if I fill it out for testing. It did not behave like that before. Any idea?
Hardy
@Hardy - Oh I didn't notice, your selector should be listening on the `<form>` element itself, so `this` is correct inside, change `#contact_form` to `#form`.
Nick Craver
@Nick - Thank you so much for your help. You taought me a lot. I liked your cleaner code than the one I have used before but I have combined that with the visuel effect approach from @FreekOne. So I took the best from the both of you guys. I am very thankful and the result still can be viewed under the link I have posted. Cheers...
Hardy
@Hardy - welcome :)
Nick Craver
+1  A: 

The problem is that your #formResponse container is not hidden at first. As soon as the response text is inserted into it, it will show directly, instead of fading it in. You need to declare display: none; to hide it:

<div class="contact-form-text" id="formResponse" style="display: none;"></div>

The AJAX callback function will then insert the text into it, and then fade it in.


UPDATE: If you want BOTH the slide and the the fade in, then you will need to use an extra response container, because once it slides out, it IS already visible and it can't fade in from 100% visibility. So what you want would be something like this:

<div id="formResponse_container" style="display:none;"> <!-- extra wrapper -->
    <div id="formResponse" class="contact-form-text" style="display:none;"></div>
</div>

and then in the jQuery script, instead of

$("#formResponse").hide().html(data).show('slow'); //hide before slide!

you would have

$("#formResponse_container").slideDown("slow", function() {
    $("#formResponse").html(data).fadeIn("slow");
});

What that does is, it will first slide down the outer container, and once that animation is completed, it will fade in the inner container.

Live example

Hope this helps.

FreekOne
@FreekOne - actually it was set to display:none. Please view here <http://jsfiddle.net/YhMWK> what I use on that panel and check again my link to the panel itself. It is just not happen. The panel slides out but there is no fadeIn at all.
Hardy
@Hardy - please see my updated answer.
FreekOne
@FreekOne - Yes, you are right, this is the way to do and I already did it. Works like a charme. I combined it with the initial approach solution from @Nick because I think the code is much cleaner and straight forward but I combined it with your approach for the visuel effect because it is better to control. I like the result. It still can be viewed under the link I posted. Thanks again for your help. ???? How to accept to answers here? Doesn´t seem to be possible.
Hardy
@Hardy - Glad to be of help !
FreekOne