联系表格不与谢谢您的消息

时间:2014-03-09 16:36:52

标签: javascript php html forms contact

可以在链接上找到此联系人的HTML和PHP,一切正常,我只想在按下“提交”按钮时收到“谢谢”或类似信息。我不担心最终结果是否发送电子邮件。它仅用于演示目的。

为了让我保留在给定字段为空白时出现的错误框,需要进行哪些修改?

谢谢

代码:

<script language="javascript">
    var sa_email_id = '1388-fc728';
    var sa_sent_text = 'Thank you for contacting us. We will get back to you soon.';
</script>

<script language="javascript" src="http://s1.smartaddon.com/sa_htmlform.js"></script>

<div id="sa_contactdiv">
    <form name=sa_htmlform style="margin:0px" onsubmit="return sa_contactform()">
    <table>
        <tr>
        <td>
            Title:<br>
            <select name="title" size="1">
                <option value="">Select</option>
                <option value="Mr.">Mr.</option>
                <option value="Mrs.">Mrs.</option>
                <option value="Miss">Miss</option>
                <option value="Ms.">Ms.</option>
                <option value="Dr.">Dr.</option>
                <option value="Prof.">Prof.</option>
                <option value="Other">Other</option>
            </select>
        </td></tr>
        <tr><td>
            Name:<br>
            <input type="text" name="name" />
        </td></tr>
        <tr><td>
            E-mail Address: <span style="color:#D70000">*</span><br>
            <input type="text" name="email" required="true" />
        </td></tr>
        <tr><td>
            Subject: <span style="color:#D70000">*</span><br>
            <input type="text" name="subject" required="true" />
        </td></tr>
        <tr><td>
            Message: <span style="color:#D70000">*</span><br>
            <textarea name="message" cols="42" rows="9" required="true">
            </textarea>
        </td></tr>
        <tr><td>
            <input type="submit" value="Send Message" style="font-weight:bold">
        </td></tr>
    </table>
    </form>

    <div style="padding-top:10px">
        <a href="http://www.smartaddon.com/contact_form.html">Contact Form</a> provided by SmartAddon.com
    </div>
</div>

Sa_htmlform: Sa_contactform:

var sa_params='';
function sa_contactform(){
var sa_frm=document.sa_htmlform;
for(i=0; i<sa_frm.elements.length; i++){
var sa_el=sa_frm.elements[i];if(sa_frm.elements[i].name){sa_params+='&'+sa_frm.elements[i].name+'='+encodeURIComponent(sa_frm.elements[i].value);}
if(!sa_el.value && sa_el.getAttribute('required')=='true'){alert('Please complete all required fields');sa_el.focus();return false;}
}
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src','http://www.smartaddon.com/js/postform.js');
document.body.appendChild(s);
return false;
}
function sa_contactsent(){
if(typeof sa_sent_text=='undefined'){sa_sent_text='Thank you for contacting us. We will get back to you soon.';}
document.getElementById('sa_contactdiv').innerHTML=sa_sent_text+'<br><br>Contact Form provided by SmartAddon.com';
}

JS:

sa_params + =''; sa_params + =''; sa_params + =''; sa_params + =''; sa_params + =''; var sa_iframe = document.createElement(“iframe”); document.body.appendChild(sa_iframe); sa_iframe.setAttribute('style','width:1px; height:1px; display:none'); var sa_frmcode =' '+ sa_params +' &lt;'+'script language =“javascript”&gt; document.pgfrm.submit()&lt;'+'/ script&gt;'; sa_iframe.contentWindow.document.write(sa_frmcode); sa_contactsent();

1 个答案:

答案 0 :(得分:0)

我不知道,如果我理解你的问题。 但是如果您不关心输入到表单中的数据会发生什么,并且只是想要一条消息,表单中是否有某些内容,请尝试以下操作:

<script language="javascript">
    var sa_sent_text = 'Thank you for contacting us. We will get back to you soon.';
    function sendme() {
        alert(sa_sent_text);
        document.getElementById("name").value = "";
        document.getElementById("message").value = "";
        document.getElementById("subject").value = "";
        document.getElementById("email").value = "";
        return false;
    }
</script>

<div id="sa_contactdiv">
    <form name=sa_htmlform style="margin:0px" onsubmit="return sendme();">
    <table>
        <tr>
        <td>
            Title:<br>
            <select name="title" size="1">
                <option value="Mr.">Mr.</option>
                <option value="Mrs.">Mrs.</option>
                <option value="Miss">Miss</option>
                <option value="Ms.">Ms.</option>
                <option value="Dr.">Dr.</option>
                <option value="Prof.">Prof.</option>
                <option value="Other">Other</option>
            </select>
        </td></tr>
        <tr><td>
            Name:<br>
            <input type="text" name="name" id="name" />
        </td></tr>
        <tr><td>
            E-mail Address: <span style="color:#D70000">*</span><br>
            <input type="text" name="email" id="email" required="true" />
        </td></tr>
        <tr><td>
            Subject: <span style="color:#D70000">*</span><br>
            <input type="text" name="subject" id="subject" required="true" />
        </td></tr>
        <tr><td>
            Message: <span style="color:#D70000">*</span><br>
            <textarea name="message" id="message" cols="42" rows="9" required="true">
            </textarea>
        </td></tr>
        <tr><td>
            <input type="submit" value="Send Message" style="font-weight:bold">
        </td></tr>
    </table>
    </form>
</div>