Codigo HTML
Código:
Codigo javascript<!-- SUBSCRIPTION FORM --> <form id="subscribe-form"> <input type="text" placeholder="introduce tu email para recibir nuestras noticias" id="subscribe-email"><input type="submit" value="suscribete" id="subscribe-submit"> </form> <!-- /SUBSCRIPTION FORM -->
Código:
Gracias de antemano var messages = config.subscription, $form = $('#subscribe-form'), $email = $('#subscribe-email'), $button = $('#subscribe-submit'), $tooltip = $('#subscribe-tooltip'); $form.submit(function(event) { event.preventDefault(); var error = false, email = $email.val(); if($tooltip.length == 0) { $tooltip = $('<p id="subscribe-tooltip" class="subscribe-tooltip"></p>'); } else { $tooltip.removeClass('error success'); } if(email.length == 0) { $tooltip.text(messages['empty_email']).addClass('error').appendTo($form); } else { $button.attr('disabled', 'disabled'); $.post('subscribe.php', { 'email': email, 'ajax': 1 }, function(data) { if(data == null || typeof(data.status) == 'undefined' || (data.status == 'error' && typeof(data.error) == 'undefined')) { $tooltip.text(messages['default']).addClass('error').appendTo($form); } else if(data.status == 'success') { $tooltip.text(messages['success']).addClass('success').appendTo($form); } else { var error_text = messages['default_error']; switch(data.error) { case 'empty_email': case 'invalid_email': error_text = messages[data.error]; break; } $tooltip.text(error_text).addClass('error').appendTo($form); } $button.removeAttr('disabled'); }, 'json'); } });