表格信息提示 [英] Form message alert

查看:116
本文介绍了表格信息提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形式:

 <形式方法=邮报行动=contactus.phpNAME =myForm的自动完成=关闭>
            <标签=名称>名称:< /标签>
            <输入类型=文本名称=名称ID =名称最大长度=60需要/>

            <标签=电子邮件>电子邮件:LT; /标签>
            <输入类型=文本名称=电子邮件ID =电子邮件最大长度=120要求/>

            <标签=消息>消息:< /标签>< BR />
            < textarea的名字=消息行=20COLS =20ID =消息需要>< / textarea的>

            <输入类型=提交名称=提交值=提交级=提交键/>

        < /形式GT;
 

和一些PHP发送电子邮件,PHP是在同一页面的形式(contactus.php)上,我想消息给地方上来的页面(未弹出,请)告诉用户对有邮件已发送(邮件不需要验证,只是当按钮为pressed)。这可以在PHP,AJAX或者JS来完成,我不介意

解决方案

 <形式方法=邮报行动=?contactus.php消息= OKNAME =myForm的自动完成=关闭>
    <标签=名称>名称:< /标签>
    <输入类型=文本名称=名称ID =名称最大长度=60需要/>

    <标签=电子邮件>电子邮件:LT; /标签>
    <输入类型=文本名称=电子邮件ID =电子邮件最大长度=120要求/>

    <标签=消息>消息:< /标签>< BR />
    < textarea的名字=消息行=20COLS =20ID =消息需要< / textarea的>

    <输入类型=提交名称=提交值=提交级=提交键/>
< /形式GT;
< D​​IV ID =displayMessage>< / DIV> *****************新的div显示邮件把任何你想要的********* *********
 

JavaScript的:

 <脚本>
        功能getParameterByName(名字){
            名称= name.replace(/ [。\ [] /,\\)取代(/ [\] /,\\]);
            变种的regex ​​=新正则表达式([?\\&安培;]+名称+=([^&安培;#] *)),
            结果= regex.exec(location.search);
            返回结果===空? :德codeURIComponent(结果[1] .replace(/ \ + /克,));
        }
        如果(getParameterByName(消息)==确定)
        {
            。的document.getElementById(displayMessage)的innerHTML =信息已发出。;
            window.alert(信息已发出。); //如果你想要一个警告框
        }
<脚本>
 

只要把<脚本>< / SCRIPT> 在你的身体到底...

I have the following form:

<form method="post" action="contactus.php" name="myForm" autocomplete="off">
            <label for="Name">Name:</label>
            <input type="text" name="Name" id="Name" maxlength="60" required/>

            <label for="email">Email:</label>
            <input type="text" name="email" id="email" maxlength="120" required/>

            <label for="message">Message:</label><br />
            <textarea name="message" rows="20" cols="20" id="message" required></textarea>

            <input type="submit" name="submit" value="Submit" class="submit-button" />

        </form>

And some PHP that sends the email, the PHP is on the same page as the form (contactus.php), and I want a message to come up somewhere on the page (not a pop up please) to tell the user there email has been sent (the email doesn't need to be validated, just for when the button is pressed). This can be done in PHP, AJAX or JS I don't mind

解决方案

<form method="post" action="contactus.php?message=ok" name="myForm" autocomplete="off">
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" maxlength="60" required/>

    <label for="email">Email:</label>
    <input type="text" name="email" id="email" maxlength="120" required/>

    <label for="message">Message:</label><br />
    <textarea name="message" rows="20" cols="20" id="message" required</textarea>

    <input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div id="displayMessage"></div>*****************new div to display message put wherever you want******************

Javascript:

<script>
        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
            var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
            return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        }
        if(getParameterByName("message") == "ok")
        {
            document.getElementById("displayMessage").innerHTML = "Message Sent.";
            window.alert("Message Sent.");//If you want an alert box
        }
<script>

Just put the <script></script> at the end of your body...

这篇关于表格信息提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆