SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    I want to display success message after form submission without changing URL

    I will be very glad if I can get a tip on how I can display success message after form submission with changing URL in PHP...just the idea to start off

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    334
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    With or without changing URL? I am confused...

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hall of Famer View Post
    With or without changing URL? I am confused...

    I mean without changing URL....I want the success message to display at the top of the form

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    am a newbie...help pls.....

  5. #5
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need to learn first to submit a form using AJAX.
    http://stackoverflow.com/questions/4...jax-and-jquery

    And then on success you write your message.
    You can use alert() to display your message.
    I Love coding...
    Don't click this link.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh, am new to web development...is there any other way I can do that in PHP? I want user without JavaScript enable to see the success message on the same page the form is submitted

  7. #7
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    497
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    IF php processing is above output (as it should be), it should be easy to set a variable if for example DB was updated etc.

  8. #8
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,588
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by aosworks View Post
    is there any other way I can do that in PHP?
    Certainly. You can place the form processing code on the contact page itself, and instead of redirecting to a thanks page on submission, you can just output the thanks message on the contact page itself.

  9. #9
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Ajax to do that - http://www.w3schools.com/ajax/, click change content in exemple to see what you need

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by solidcodes View Post
    You can use alert() to display your message.
    Why use a debugging call to display the message?

    Alerts look like this in Opera:

    alert.gif

    and like this in Firefox and Chrome

    alert2.gif

    Note the checkbox for turning off JavaScript for debugging infinite loops or for turning off subsequent alerts for debugging loops with a high number of passes.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @felgall ;
    There is nothing I can say regarding JS, you are far better than me. lol
    Anyway I use it personally.
    I Love coding...
    Don't click this link.

  12. #12
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Certainly. You can place the form processing code on the contact page itself, and instead of redirecting to a thanks page on submission, you can just output the thanks message on the contact page itself.

    Thanks everyone....if I want to place my form processing code on the contact page itself...what will be the value of my action attribute within the form element? and the success message is already output without submitting the form yet...pls help

  13. #13
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    497
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form action="" method="post">
    The success message should only be defined on successful processing of POST data. Then above the form you could have something like
    PHP Code:
    <?php
    if (isset($success_message)){ echo $success_message;}
    ?>

  14. #14
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Drummin View Post
    HTML Code:
    <form action="" method="post">
    The success message should only be defined on successful processing of POST data. Then above the form you could have something like
    PHP Code:
    <?php
    if (isset($success_message)){ echo $success_message;}
    ?>
    My PHP code

    PHP Code:
    $message " ";
    $fullName $_POST["fullName"] ;
    $email $_POST["email"];
    $formMessage $_POST["message"];


    $message .= "Full Name: " $fullName "\n"
    $message .= "Email Address: " $email "\n"
    $message .= "Comment: " $formMessage "\n";

    $subject "Contact Us";
    $myEmail =" name@example.com";

    $success mail($myEmail$subject$message); 


    My HTML markup
    HTML Code:
    <div>if (isset($success)) {
    
    echo "Message successfully sent";
    }
    else {
    
    echo  "Message Sending Failed, try again";
    }   </div>
    
    <form method="post" action="" id="contactForm">
    <div>
    <label for="fullName">Name: </label>
    <input type="text" name="fullName" id="fullName" required="required" />
    </div>
    				
    <div>
    <label for="Email">Email address:</label>
    <input type="email" name="email" id="email" required="required" placeholder="name@example.com" />
    </div>
    			
    <div>
    <label for="message">Idea / Question / Comments:</label>
    <textarea name="message" id="message" rows="5" cols="20"></textarea>
    </div>
    			
    <div class="submit">
    <input type="submit" name="contactSubmit" id="contactSubmit" value="Send Message" />
    </div>
    </form>


    With this code above I have the success message display already on the page without even submit the form yet...

    Please help me out with any error within the HTML and PHP code...I just want the success message to display on the same page without changing URL

  15. #15
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    497
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    if(isset($_POST['contactSubmit'])){
        
    $message " ";
        
    $fullName $_POST["fullName"] ;
        
    $email $_POST["email"];
        
    $formMessage $_POST["message"];
        
        
        
    $message .= "Full Name: " $fullName "\n"
        
    $message .= "Email Address: " $email "\n"
        
    $message .= "Comment: " $formMessage "\n";
        
        
    $subject "Contact Us";
        
    $myEmail =" name@example.com";
        
        if (
    mail($myEmail$subject$message)){
            
    $success "Message successfully sent";
        }else{
            
    $success "Message Sending Failed, try again";
        }

    ?>
    <html>
    <body>
    <?php
    if (isset($success)){ echo "<div>" $success "</div>";}
    ?>
        <form method="post" action="" id="contactForm">
            <div>
                <label for="fullName">Name: </label>
                <input type="text" name="fullName" id="fullName" required="required" />
            </div>
                            
            <div>
                <label for="Email">Email address:</label>
                <input type="email" name="email" id="email" required="required" placeholder="name@example.com" />
            </div>
                        
            <div>
                <label for="message">Idea / Question / Comments:</label>
                <textarea name="message" id="message" rows="5" cols="20"></textarea>
            </div>
                        
            <div class="submit">
                <input type="submit" name="contactSubmit" id="contactSubmit" value="Send Message" />
            </div>
        </form>
    </body>
    </html>

  16. #16
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,617
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    I want to display success message after form submission without changing URL

    Here is a simple one page script. http://www.websitecodetutorials.com/...ntact-form.php

    Here is a more difficult multipage script with full validation (php and js) and captcha http://www.websitecodetutorials.com/...validation.php

  17. #17
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    497
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Probably should add some headers.
    PHP Code:
    <?php
    if(isset($_POST['contactSubmit'])){
        
    $message " ";
        
    $fullName $_POST["fullName"] ;
        
    $email $_POST["email"];
        
    $formMessage $_POST["message"];
        
        
        
    $message .= "Full Name: " $fullName "\n"
        
    $message .= "Email Address: " $email "\n"
        
    $message .= "Comment: " $formMessage "\n";
        
        
    $subject "Contact Us";
        
    $myEmail =" name@example.com";
        
        
    $headers "From: \"$fullName\" <$email>\r\n";
        
    $headers .= "Reply-To: $email\r\n";
        
    $headers .= "X-Sender: $email \r\n";
        
    $headers .= "X-Priority: 3 \r\n";
        
    $headers .= "X-Mailer: php\r\n";
        
        if (
    mail($myEmail$subject$message$headers)){
            
    $success "Message successfully sent";
        }else{
            
    $success "Message Sending Failed, try again";
        }

    ?>
    <html>
    <body>
    <?php
    if (isset($success)){ echo "<div>" $success "</div>";}
    ?>
        <form method="post" action="" id="contactForm">
            <div>
                <label for="fullName">Name: </label>
                <input type="text" name="fullName" id="fullName" required="required" />
            </div>
                            
            <div>
                <label for="Email">Email address:</label>
                <input type="email" name="email" id="email" required="required" placeholder="name@example.com" />
            </div>
                        
            <div>
                <label for="message">Idea / Question / Comments:</label>
                <textarea name="message" id="message" rows="5" cols="20"></textarea>
            </div>
                        
            <div class="submit">
                <input type="submit" name="contactSubmit" id="contactSubmit" value="Send Message" />
            </div>
        </form>
    </body>
    </html>

  18. #18
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    28
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Drummin View Post
    PHP Code:
    <?php
    if(isset($_POST['contactSubmit'])){
        
    $message " ";
        
    $fullName $_POST["fullName"] ;
        
    $email $_POST["email"];
        
    $formMessage $_POST["message"];
        
        
        
    $message .= "Full Name: " $fullName "\n"
        
    $message .= "Email Address: " $email "\n"
        
    $message .= "Comment: " $formMessage "\n";
        
        
    $subject "Contact Us";
        
    $myEmail =" name@example.com";
        
        if (
    mail($myEmail$subject$message)){
            
    $success "Message successfully sent";
        }else{
            
    $success "Message Sending Failed, try again";
        }

    ?>
    <html>
    <body>
    <?php
    if (isset($success)){ echo "<div>" $success "</div>";}
    ?>
        <form method="post" action="" id="contactForm">
            <div>
                <label for="fullName">Name: </label>
                <input type="text" name="fullName" id="fullName" required="required" />
            </div>
                            
            <div>
                <label for="Email">Email address:</label>
                <input type="email" name="email" id="email" required="required" placeholder="name@example.com" />
            </div>
                        
            <div>
                <label for="message">Idea / Question / Comments:</label>
                <textarea name="message" id="message" rows="5" cols="20"></textarea>
            </div>
                        
            <div class="submit">
                <input type="submit" name="contactSubmit" id="contactSubmit" value="Send Message" />
            </div>
        </form>
    </body>
    </html>



    @Drummin thanks so much for your time and thinking...everything is working fine now, I can now display the success message on the same page without changing the url...thanks so much...I hope to see you again in future for help cause am new to web development and I believe that there is more you can show me... thanks once again... and everyone too...thanks all.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •