2014-01-07 129 views
0

下面的代碼實際上提交併與我需要顯示一個警告框顯示消息已發送相同。如何顯示警告框?

代碼:

<input type="button" class="Jdvs_Btn" onclick="send_reply('SEND_REPLY', <? echo $clsSurvey->feedback_id?>);" value="SEND" style="font-weight:bold;width:95px;height:30px;float:left; margin-right:5px;" /> 

和JavaScript

代碼:

if(action == "SEND_REPLY") 
{ 
if(frm.email.value == "") 
{ 
    alert("Please fill your email."); 
    frm.email.focus(); 
    return false; 
} 
else if(validateEmailAddress(frm.email.value) == false) 
{ 
    alert("Please fill a valid email."); 
    frm.email.focus(); 
    return; 
} 
else if ((tinymce.EditorManager.get('content_to_send').getContent()) == '') 
{ 
    alert("Please enter content to send."); 
    return; 
} 
else 
{ 
    frm.form_action.value = action; 
    frm.submit(); 
    alert('Message Sent Successfully'); 
} 

}

郵寄的代碼是: 這是驗證等是完成,我需要在這裏顯示一個警告框 代碼:

function sendReply() 
{ 
    echo $this->feedback_id; 
    $this->checkAndUpdateReply($this->feedback_id,$this->content_to_send); 
    $Message = nl2br($this->content_to_send); 
    $mailMessage = " 
    <html> 
    <head> 
    <title>constant('_SHORT_PRODUCT_NAME') - Feedback Mail</title> 
    </head> 
    <body>"; 
      $Message = nl2br($this->content_to_send); 
     $mailMessage.= $Message." 
    <table border='0' cellpadding='0' cellspacing='0'width='100%'> 
    <tr> 
    <td style='$css_class' align='left'><br/>Email: "._EMAIL_INFO."</td> 
     </tr> 
     <tr> 
     <td style='$css_height' align='left'><br /><b>Note</b>:- This is an automatically generated email , Please dont reply back to this mail.</td> 
    </tr> 
     </table> 
    </body> 
    </html>";  
    $mailSubject= constant('_SHORT_PRODUCT_NAME').' - FeedBack Reply'; 
    $clsEmailTempalte = new clsEmailTemplate($connect, ""); 
    $clsEmailTempalte->sendMail($mailSubject,$mailMessage,$this->email); 
} 
+0

歡迎來到SO,你的代碼到目前爲止? – Goikiu

回答

2

在你send_reply年底javascript函數如果您正在使用AJAX只是做一個alert("Mail Sent");

(例如與jQuery)你需要添加你的警報到回調。

的jQuery:

var jqxhr = $.ajax("example.php") 
    .done(function() { 
    alert("success"); 
    }) 
+1

它只是顯示郵件發送前的警告框 –

+0

如果JavaScript得到這一點,該消息已發送,假設您正在上面運行您的ajax調用。 –

+0

if(frm.email.value ==「」) { \t alert(「Please fill your email。」); \t return false; }否則 \t \t \t { \t \t \t \t \t \t \t frm.form_action.value =行動; \t \t \t \t frm。提交(); \t \t \t \t alert('Message Sentfullyfully'); \t \t \t} –

0

在你的JavaScript功能send_reply剛纔添加的行

alert("Message sent"); 

應該工作。

0

只需在您的js函數的末尾添加alert("message has been sent");即可。

0

如果我這樣做(使用jQuery)。我會打電話發送用ajax像這樣的電子郵件的PHP文件:

你的HTML:

<input type='button' id='submit_form' data-id='<? echo $clsSurvey->feedback_id?>' /> 

你的JavaScript:

$('#submit_form').click(function(e){ 

    // To stop the form submitting on button click if you want it to... 
    e.preventDefault(); 

    // Send the id via post to the mailscript 
    $.ajax({ 
     url: 'mailscript.php', 
     type: 'POST' 
     data: { 
      id: $(this).attr('data-id') 
     } 
    }).done(function(data){ 
     // Use data if you want to return something from the script and add to the message maybe? 
     alert('Add your message in here'); 
    }); 

}); 

然後,只需添加mailscript.php內郵寄的PHP (或者任何你想稱之爲的)。每當你的腳本完成它的工作,完成功能將觸發顯示你的警報。