SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    If email sent then hide contact form div

    hi all

    On click of submit button If the email is sent, then I want to hide the contact form div.

    My below code is not hiding the contact form

    vineet

    PHP Code:
    <?php
    if(mail($to,$subject,$body,$headers))
        {
        echo 
    "<script type='text/javascript'>";
        echo 
    "hideDiv();"
        
    echo "</script>";
        
    $msg="We have received your enquiry. We will contact you soon.";
        }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function hideDiv()
    {
    document.getElementById("contact_form_div").style.display="none";
    }
    </script>
    </head>

    <body>
    <form onsubmit="return validate()">
    <!-- contact form content-->
    <input type="submit" value="submit" name="submit" />
    </form>
    </body>
    </html>

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi Vineet,

    You don't need JS to hide the form. Just set a variable with the result of the mail function:
    PHP Code:
    $emailSent FALSE;

    // The rest of your form processing code here

    if ($emailSent mail($to,$subject,$body,$headers)) {
        
    $msg="We have received your enquiry. We will contact you soon.";

    and then, in your markup further down the page, use an IF statement to only output the form if $emailSent is false:
    PHP Code:
    <?php if ($emailSent == FALSE) : ?>
    <form onsubmit="return validate()"> 
    <!-- contact form content--> 
    <input type="submit" value="submit" name="submit" /> 
    </form>
    <?php endif; ?>

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi fretburner

    Thankyou so much.

    It works great.

    thanks
    vineet


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
  •