est-il un moyen de lier le "soumettre" à la fancybox après le succès?Fancybox jQuery ajax sur la forme de liaison de succès Envoyer
Voici ce que j'ai:
<div class="ta_l" id="tell_friend">
<form id="form_tell_friend" method="post" action="">
<table cellspacing="0" cellpadding="0" border="0" class="tbl_insert mr_b0">
<tbody>
<tr class="tell_friend_email dn">
<th> </th>
<td><span class="red">Please provide a valid email address</span></td>
</tr>
<tr>
<th><label for="tell_friend_email">Email: *</label></th>
<td><input type="text" class="fld" value="" id="tell_friend_email" name="tell_friend_email" /></td>
</tr>
<tr class="tell_friend_content dn">
<th> </th>
<td><span class="red">Please provide a message</span></td>
</tr>
<tr>
<th><label for="tell_friend_content">Message: *</label></th>
<td><textarea class="tartiny" rows="" cols="" id="tell_friend_content" name="tell_friend_content"></textarea></td>
</tr>
<tr>
<th> </th>
<td>
<label class="sbm sbm_blue small" for="tell_friend_btn">
<input type="submit" value="Send" class="btn" id="tell_friend_btn" />
</label>
</td>
</tr>
</tbody>
</table>
</form>
</div>
j'appelle fancybox et faire une validation avec ajax et php:
// tell a friend form
if($('.tell-friend').length > 0) {
$('.tell-friend').fancybox({
'speedIn' : 600,
'speedOut' : 200,
'overlayShow' : true,
'scrolling' : 'no',
'titleShow' : false
});
function tellAFriend() {
$.ajax({
type : "POST",
cache : false,
url : "/message/run/tellafriend",
data : $(this).serializeArray(),
dataType: "json",
success: function(data) {
$("#form_tell_friend").bind("submit", tellAFriend);
if(data != 1) {
$.each(data, function(key, value) {
$('.' + value).fadeIn(500);
});
$.fancybox.resize();
$("#form_tell_friend").bind("submit", tellAFriend);
} else {
$.fancybox({
'scrolling' : 'no',
'content' : 'Your message has been sent successfully'
});
}
},
error: function(data) {
alert('Error occured');
}
});
return false;
}
$("#form_tell_friend").bind("submit", tellAFriend);
}
et enfin mon php:
public function tellafriendAction() {
$empty = array();
if(!empty($_POST)) {
foreach($_POST as $key => $value) {
if (empty($value)) {
$empty[] = $key;
}
}
}
if(!empty($empty)) {
echo json_encode($empty);
} else {
echo 1;
}
}
Maintenant - la validation se passe bien la première fois, mais je ne peux pas renvoyer le formulaire - si je mets des valeurs dans les champs, il affiche toujours des avertissements après avoir cliqué sur le bouton Soumettre - comme s'il ne reconnaissait pas l'événement submit.
J'ai ajouté:
$("#form_tell_friend").bind("submit", tellAFriend);
sur le succès en ajax - mais je ne pense pas que ça fonctionne - une idée?