Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jun 2008
    Location
    UK
    Posts
    53
    Thanks
    12
    Thanked 0 Times in 0 Posts

    hide html form on submission

    hi

    i have a standard html form i am using to receive information from customers. I know there are various ways of stopping a form being sent twice, but my site is all about user-friendliness so i want to go the extra mile.

    Is there any way a form can be hidden once successfully submitted, and replaced with a new, previously unseen div. I was playing around with a javascript that toggles divs but can't get it to 'stick' (ie if a user leaves the page then comes back the new div is still present, not the form).

    If anyone out there can help then

    a) theyre a pure genius
    b) ill be very grateful

    thanks

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    What processes the form?
    Have you got php installed on your server if so you could have something like this

    PHP Code:
    if(isset($_POST))
    {
     echo 
    "new div";

    }
    else
    {
     echo 
    "Form";


    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Jun 2008
    Location
    UK
    Posts
    53
    Thanks
    12
    Thanked 0 Times in 0 Posts
    that looks good, but im not good with php and dont really know where i would place that.

    the page is .php (due to my love of includes)

    this is the code for the form
    Code:
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="../formscripts/namecheck.php">
    <input name="name" type="text" size="50" />
    <input name="proposedname" type="text" size="50" />
    <input name="email" type="text" size="50" />
    </form>

    this is the code for the processing
    PHP Code:
    <?php header("Refresh: 0;url=[B]http://www  [/B]                "); ?>
    <?php
    mail
    ("address""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email")
    ?>

    <?php
    mail
    ("[B]address[/B]""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email")
    ?>

    <?php
    mail
    ("$email""Your choice of name""

    Hi $name,

    Thanks for your interest in [B]company name[/B]. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours. 

    We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: [B]from addy[/B]")
    ?>
    bold are things i chopped out of the code to post it up here - CF caches well and i dont want my customers coming across these posts!

    If theres any way to get that all on one page, with the replacement divs even better!

    Thanks
    Last edited by Jordan656; 03-30-2009 at 12:06 AM. Reason: hide domain to stop google indexing

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I'm abit confused about this line

    PHP Code:
    <?php header("Refresh: 0;url=http://example.com"); ?>
    Ive seen header("Location: "); but not refresh ill test that in a minute.
    But i think you should try
    PHP Code:
    <?php
    if(isset($_POST))
    {
    echo
    '
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
    <input name="name" type="text" size="50" />
    <input name="proposedname" type="text" size="50" />
    <input name="email" type="text" size="50" />
    </form>'
    ;
    }
    else
    {
     
    header("Refresh: 0;url=[b]http://www  [/b]                ");
    mail("address""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");

    mail("[b]address[/b]""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");
    mail("$email""Your choice of name""

    Hi $name,

    Thanks for your interest in [b]company name[/b]. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours. 

    We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: [b]from addy[/b]");
     

    }
    ?>
    Give it a try any problems then its maybe to do with that line or whatever the JS function formCheck(this); does
    Last edited by timgolding; 03-30-2009 at 12:40 AM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Ok i tesed the refresh command and it just seems to redirect to a different page does it redirect back to itself maybe? In which case it would need tobe what ever the url of that page is. Not sure if this should be done after the mail functions are called though. I mean does the email get sent. Maybe it should be

    PHP Code:
    <?php
    if(isset($_POST))
    {
    echo
    '
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
    <input name="name" type="text" size="50" />
    <input name="proposedname" type="text" size="50" />
    <input name="email" type="text" size="50" />
    </form>'
    ;
    }
    else
    {
     
    mail("address""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");

    mail("[b]address[/b]""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");
    mail("$email""Your choice of name""

    Hi $name,

    Thanks for your interest in [b]company name[/b]. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours. 

    We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: [b]from addy[/b]");
     
    header("Refresh: 0;");

    }
    ?>
    Not sure about that give it a try.
    Last edited by timgolding; 03-30-2009 at 12:49 AM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Yeah the second example would work i just tested it
    You can not say you know how to do something, until you can teach it to someone else.

  • #7
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Actually you need to completely remove that header function

    PHP Code:
    <?php
    if(isset($_POST))
    {
    echo
    '
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
    <input name="name" type="text" size="50" />
    <input name="proposedname" type="text" size="50" />
    <input name="email" type="text" size="50" />
    </form>'
    ;
    }
    else
    {
     
    mail("address""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");

    mail("[b]address[/b]""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");
    mail("$email""Your choice of name""

    Hi $name,

    Thanks for your interest in [b]company name[/b]. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours. 

    We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: [b]from addy[/b]");


    echo 
    "Place you new div here";

    }
    ?>
    and replace your output for the new div where i have shown.
    You can not say you know how to do something, until you can teach it to someone else.

  • #8
    New Coder
    Join Date
    Jun 2008
    Location
    UK
    Posts
    53
    Thanks
    12
    Thanked 0 Times in 0 Posts
    ive placed this code on my page. when the form submits the page flashes (i assume its refreshing) but no emails are sent, and no alternative div appears.

    Any suggestions?

  • #9
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Sorry I've been a little busy today with work and things. I've looked at my code and am a little ashamed of what i posted but i got it working now.
    Basically i forgot copy the post data to the variables and I got the isset condition the wrong way around it should have been (!isset($_POST)). Sorry i was in a rush to get to bed last night and did'nt really check through what i did. But i have completed the code and uploaded it to my server and it is sending the emails. It wasn't before because it was never getting to that bit of code.

    Heres the code
    PHP Code:
    <?php
    if(!isset($_POST["submit"]))
    {
    echo
    '
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
    <label>Name: </label>
    <input name="name" type="text" size="50" /><br />
    <label>Proposed Name: </label>
    <input name="proposedname" type="text" size="50" /><br />
    <label>Email: </label>
    <input name="email" type="text" size="50" /><br />
    <input type="submit" value="submit" name="submit" />
    </form>'
    ;
    }
    else
    {
     
    $email=$_POST['email'];
     
    $proposedname=$_POST['proposedname'];
     
    $name=$_POST['name'];
    mail("tim@example.com""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");

    mail("timmy@example.com""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");
    mail("timothy@example.com""Your choice of name""

    Hi $name,

    Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests recieved 9am - 9pm we aim to reply within 2 hours. 

    We have recieved the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: mail@cybadev.co.uk");


    echo 
    "Place you new div here";

    }
    ?>
    This 100% works i have tested it see for yourself http://cybadev.co.uk/email.php. If you have any problems let me know. But provided you javascript validation works there shouldn't be a problem
    Last edited by timgolding; 04-01-2009 at 01:04 AM.
    You can not say you know how to do something, until you can teach it to someone else.

  • Users who have thanked timgolding for this post:

    Jordan656 (03-31-2009)

  • #10
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I should of really pointed out that this script isn't at all secure. Although you have some javascript validation in place that won't stop a hacker sending post data by other means. You really need to implement some sever side validation. You should maybe implement some PEAR validation on the names and email otherwise a hacker might use your script to send hundreds of unsolicited emails. You especially need to validate that the email is a single email and that the string doesn't contain more than one valid email. It gets a bit risky when you are using the optional additional header in the mail function.

    Heres the validation script to download

    http://pear.php.net/package/Validate/download

    Download it, untar it. Find the file Validate.php in the package and put it in your website folder. then include it in your PHP script with
    PHP Code:
    require_once('Validate.php'); 
    You may want to add some extra characters to the punctuation regex.
    Anyway once it's included in your script. You can use it like so

    PHP Code:
    <?php
    require_once('Validate.php');

    //email validation 
    $email="tim@example.com";

    if(
    Validate::email($emailtrue)) //use true to use dns lookup 
        
    echo "Valid email";
    else
        echo 
    "Invalid email";

    // String validation. 
    //This assumes you want to allow whitespaces, punctuation, Alpha and numeric if you want too remove any of these just drop them out
    $name="Tim Golding";
    $min_length 1;
    $max_length 50;
    define('PUNCTUATION''\.,;\:&"\'\?\!\(\)');
    define('EXTRAS'"'" "-"); //extra punctuation for names
    if(Validate::string($name, array("format" => VALIDATE_EALPHA VALIDATE_NUM VALIDATE_SPACE PUNCTUATION EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length))) 
        echo 
    "Valid name";
    else
        echo 
    "Invalid name";

    ?>
    Thats some simple examples. So how to add this to your code... Like so
    PHP Code:
    <?php
    if(!isset($_POST["submit"]))
    {
    echo
    '
    <form id="form1" name="form1" method="post" onsubmit="return formCheck(this);" action="">
    <label>Name: </label>
    <input name="name" type="text" size="50" /><br />
    <label>Proposed Name: </label>
    <input name="proposedname" type="text" size="50" /><br />
    <label>Email: </label>
    <input name="email" type="text" size="50" /><br />
    <input type="submit" value="submit" name="submit" />
    </form>'
    ;
    }
    else
    {
    // Simple validation to check they are all set
    if(!isset($_POST['email'], $_POST['proposedname'], $_POST['name']))
    die (
    'You must enter an email, proposed name and a name');
     
    require_once(
    'Validate.php'); // You must put Validate.php in the same folder as this script for this to work
    //setting post data 
     
    $email=$_POST['email'];
     
    $proposedname=$_POST['proposedname'];
     
    $name=$_POST['name'];

    //And the validation shown above
    //Email validation
    if(!Validate::email($emailtrue)) //use true to use dns lookup 
      
    die("Sorry the email you entered is invalid");

    //names validation    
    $min_length 1;
    $max_length 50;
    define('PUNCTUATION''\.,;\:&"\'\?\!\(\)');
    define('EXTRAS'"'" "-"); //extra punctuation for names
    if(!Validate::string($name, array("format" => VALIDATE_EALPHA VALIDATE_NUM VALIDATE_SPACE PUNCTUATION EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length))) 
       die(
    "Sorry the name your entered is invalid");

    if(!
    Validate::string($proposedname, array("format" => VALIDATE_EALPHA VALIDATE_NUM VALIDATE_SPACE PUNCTUATION EXTRAS ,"min_length" => $min_length ,"max_length" => $max_length))) 
        die(
    "Sorry the proposedname your entered is invalid");

    mail("tim@example.com""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");

    mail("timmy@example.com""Name check $name to $proposedname""

    Please check the following change of name will be acceptable, and reply to the customer as soon as possible:

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Thankyou.
     "
    ,"From: $email");
    mail("timothy@example.com""Your choice of name""

    Hi $name,

    Thanks for your interest in company name. We have recieved your request for advice on your change of name. A member of our team will review the information you have sent and get back to you as soon as possible. For requests received 9am - 9pm we aim to reply within 2 hours. 

    We have received the following information. If any details are incorrect please reply to this email with the correct information.

    Name: $name
    Proposed name: $proposedname
    Email address: $email

    Many thanks


     "
    ,"From: mail@cybadev.co.uk");


    echo 
    "Place you new div here";

    }
    ?>
    There you have it hacker proof code. Though it just exits with an error message if its invalid. You may want to do something more exciting here?
    Last edited by timgolding; 04-01-2009 at 01:03 AM.
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

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