最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to make a javascript or php SUCCESS message appear after optin form has been submitted - Stack Overflow

programmeradmin1浏览0评论

I am using a custom optin page with a form , Currently the form works like this USER SUBMITS > PAGE REFRESHES FOR HIM > I GET AN EMAIL WITH THE SUBMITTED DATA.

But the user does not get a confirmation message, So most of the times , Users re submit the form thinking it did not worked at the 1st time.

I want to add a Popup/Javascript Success Message to it OR After hitting submit , the user gets redirected to another page .

This is the current form code

<div class="form fix ">
                    <p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
                    <form name="contactform" action="mail-script.php" method="POST">
                        <label for="fname">First Name:
                            <input type="text" name="fname" id="fname" />
                        </label><br>
                        <label for="lname">Last Name:
                            <input type="text" name="lname" id="lname" />
                        </label><br>
                        <label for="email">Email Address:
                            <input type="text" name="email" id="email" />
                        </label><br>
                        <label for="phone">Phone Number:
                            <input type="text" name="phone" id="phone" />
                        </label><br>
                        <label for="phone">Alternate Phone:
                            <input type="text" name="phone" id="aphone" />
                        </label><br>
                        <label for="resort">Resort Name:
                            <input type="text" name="resort" id="resort" />
                        </label><br>
                        <label for="amount">Amount Owed? $:
                            <input type="number" name="amount" id="amount" />
                            <p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
                            If Paid Off Leave Zero, Else Put Amount</p>
                        </label><br>
                        <div class="checkbox">
                            <div class="check-text fix">
                                <p>I'm Considering To</p>
                            </div>
                            <div class="check-one fix">
                                <input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
                                <input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
                                <input type="checkbox" name="call" id="" value="rent "/> Rent  It 
                            </div>
                            <div class="check-two fix">
                                <input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
                                <input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
                                <input type="checkbox" name="call" id="" value="give"/> Give It Back
                            </div>
                        </div>

                                                 <p class="captcha">
                            <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
                            <label for='message'>Enter the code above here :</label><br>
                            <input id="6_letters_code" name="6_letters_code" type="text"><br>
                            <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
                        </p>
                        <input id="submit" type="submit" value="" />
                        <p class="submit-text">Ensure all fields are pleted and correct, allowing you more benefits, while preventing abuse of our data.</p>
                    </form>
                </div>
            </div>

This is the online url of the form .html

**********************UPDATE******************************

I am using a custom optin page with a form , Currently the form works like this USER SUBMITS > PAGE REFRESHES FOR HIM > I GET AN EMAIL WITH THE SUBMITTED DATA.

But the user does not get a confirmation message, So most of the times , Users re submit the form thinking it did not worked at the 1st time.

I want to add a Popup/Javascript Success Message to it OR After hitting submit , the user gets redirected to another page .

This is the current form code

<div class="form fix ">
                    <p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
                    <form name="contactform" action="mail-script.php" method="POST">
                        <label for="fname">First Name:
                            <input type="text" name="fname" id="fname" />
                        </label><br>
                        <label for="lname">Last Name:
                            <input type="text" name="lname" id="lname" />
                        </label><br>
                        <label for="email">Email Address:
                            <input type="text" name="email" id="email" />
                        </label><br>
                        <label for="phone">Phone Number:
                            <input type="text" name="phone" id="phone" />
                        </label><br>
                        <label for="phone">Alternate Phone:
                            <input type="text" name="phone" id="aphone" />
                        </label><br>
                        <label for="resort">Resort Name:
                            <input type="text" name="resort" id="resort" />
                        </label><br>
                        <label for="amount">Amount Owed? $:
                            <input type="number" name="amount" id="amount" />
                            <p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
                            If Paid Off Leave Zero, Else Put Amount</p>
                        </label><br>
                        <div class="checkbox">
                            <div class="check-text fix">
                                <p>I'm Considering To</p>
                            </div>
                            <div class="check-one fix">
                                <input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
                                <input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
                                <input type="checkbox" name="call" id="" value="rent "/> Rent  It 
                            </div>
                            <div class="check-two fix">
                                <input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
                                <input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
                                <input type="checkbox" name="call" id="" value="give"/> Give It Back
                            </div>
                        </div>

                                                 <p class="captcha">
                            <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
                            <label for='message'>Enter the code above here :</label><br>
                            <input id="6_letters_code" name="6_letters_code" type="text"><br>
                            <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
                        </p>
                        <input id="submit" type="submit" value="" />
                        <p class="submit-text">Ensure all fields are pleted and correct, allowing you more benefits, while preventing abuse of our data.</p>
                    </form>
                </div>
            </div>

This is the online url of the form http://timesharesgroup./sell/index.html

**********************UPDATE******************************

Share Improve this question edited Mar 25, 2015 at 12:50 Lost Sould asked Mar 25, 2015 at 6:34 Lost SouldLost Sould 1271 gold badge3 silver badges13 bronze badges 2
  • Please use php flash message functionality. That means when your form submits successfully show flash message on the same page by setting it in your session.Read php manual how to do this. – Death-is-the-real-truth Commented Mar 25, 2015 at 6:43
  • You can keep a hidden field in your next page, I mean once the form is submitted and after success it will redirect to some page right? so in that page keep a hidden field and set it's value on page load. You can set it's value with a session value. Like once the form is posted and its success, set a session variable and in next page check if that session has value and if it has value set a success value to your hidden field and then write a document.ready function to check your hidden field value and show the success message div if the value exists in that hidden field. – Guruprasad J Rao Commented Mar 25, 2015 at 6:43
Add a ment  | 

3 Answers 3

Reset to default 2

If you want just a normal pop up button, you could do the following :

$('form').on('submit',function(){
           alert('submitted');
});

If you want a fancier way to do things, you can use AJAX. You could add to your HTML a hidden div with id success, and you do the following:

<span class="success">Thank's for submitting the form</span>

and AJAX is :

$(document).ready(function() {
    $("form[name='contactform']").submit(function() {

        // do the extra stuff here
        $.ajax({
            type: "POST",
            url: "mail-script.php",
            data: $(this).serialize(),
            success: function() {
                $('.success').fadeIn(100).show();

            }
        })

    })
})

You can give appropriate message on form submit event through below function. you can even stop form submitting through event.preventDefault(); if you mentioned inside function.

$( "form" ).submit(function( event ) {
alert( "Handler for submit() called." );
window.location.href="another html page";
});

when a user click your url like www.site./index.php the form will ing. when a user fill the data and click on submit the url showing like this www.site./mail-script.php but i am asking Where is your code for mail-script.php

under this file bottom you can add this line of code.

header('Location: thankyou.php');

and create your own thankyou.php file like this

<html>

<body>
       <h1>Mail delivery success. Touch you soon...</h1>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论