将表单数据传递到重定向页面 - javascript - jQuery

时间:2018-02-14 18:03:45

标签: javascript jquery

             <div class="box-wrapper">
                <form method="POST" action="/cgi-bin/formmail/FormMail.pl">
                    <input type="hidden" name="recipient" value="mail123@gmail.com">
                    <input type="hidden" name="subject" value="Contact Form">
                    <input type="hidden" name="redirect" value="http://127.0.0.1/contact.html?formsubmit=success">
                    <input type="text" name="name" placeholder="Name" required="">
                    <input type="email" name="email" placeholder="Email Id" required="">
                    <input type="text" name="mobile" maxlength="10" placeholder="Mobile Number" id="number" required="">
                    <input name="service" list="services" placeholder="What service you need?" required>
                    <datalist id="services">
                        <option value="Web Design">Web Design</option>
                        <option value="Graphic Design">Graphic Design</option>
                        <option value="UI/UX Design">UI/UX Design</option>
                        <option value="Digita Marketing">Digital Mareketing</option>
                        <option value="Others">Others</option>
                    </datalist>
                    <textarea placeholder="Additonal detail" name="details" required=""></textarea>
                    <button type="submit" name="submit" id="submit-btn" onclick="thanksMsg()"><i class="fa fa-send"></i></button>
                </form>
                <div id="thanksmsg"></div>
            </div>

这是我的html代码。我在提交后将表单数据传递给我的邮件。并重定向到“http://127.0.0.1/contact.html?formsubmit=success”。在这个页面上,我使用jQuery显示感谢msg。

<script type="text/javascript">
    $(document).ready(function(){
        var url = window.location.href;
        var text = $('#form').find('input[name="name"]').val();
        if(url == 'http://127.0.0.1:8887/contact.html?formsubmit=success'){
            var name = $('#form').find('input[name="name"]').val();
            $('#thanksmsg').append('<p>Hi'+text+', Thanks for reaching us out. <br>We will get back to you shortly </p><div><a class="cta-btn">Back to home</a><a class="cta-btn">View our Portfolio<a></div>');
            $('form').css('display', 'none');
        }
    }); 
</script>

这里感谢msg我想显示在输入字段中输入的名称。但是当它被重定向时它不会出现。如何显示名称?

1 个答案:

答案 0 :(得分:0)

尝试使用Cookie。在提交表单中,写下$.cookie('name', name)之类的内容。要恢复,请致电$.cookie('name')。 我不确定它是否有效,因为在某些情况下,cookie会被删除,但很容易尝试。