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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Copy / Paste simple code for PHP form?

    Could someone please help me with a very simple form that I can just copy and paste that includes a drop down menu, a text area, and a series of checkboxes ("choose all that apply"). I would like for the results to be e-mailed to me upon clicking submit. I have a basic understanding of forms so bear with me.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    Not enough information
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by myfayt View Post
    Not enough information
    What else would you need? I have a similar working form and this description is pretty straight forward.

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    You might get a better response if you show us what you have tried so far. Barring that, you might as well search Google for some form generators and just run with that.

    You know by now that most people here are keen to help, but not so keen on providing spoon-fed code.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #5
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Rowsdower! View Post
    You might get a better response if you show us what you have tried so far. Barring that, you might as well search Google for some form generators and just run with that.

    You know by now that most people here are keen to help, but not so keen on providing spoon-fed code.
    I tried previously to get help with my current code but everyone has different methods and it became a jumbled mess so I figured we'd go from scratch. The working form I do have is so incredibly simple and short that I wouldn't have a problem giving it away to someone that didn't know how to do it. I'll PM you my code and the single problem it's giving me if you want to help with it that way.

  • #6
    New Coder
    Join Date
    Nov 2011
    Location
    New England
    Posts
    62
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by cineweekly.com View Post
    Could someone please help me with a very simple form that I can just copy and paste that includes a drop down menu, a text area, and a series of checkboxes ("choose all that apply"). I would like for the results to be e-mailed to me upon clicking submit. I have a basic understanding of forms so bear with me.
    Try this.

    action.php:

    PHP Code:

    <?php

    if ( empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'] ) ) 

        die(
    "Some required fields were missing. Go back and try again");
    }

    $your_email 'YOUR_MAIL_HERE@website.com';
    $name $_POST['name'];
    $email $_POST['email'];
    $option1 $_POST['option1'];
    $option2 $_POST['option2'];
    $message $_POST['message'];


    if (    
    mail($your_email"Message from $name""Name: $name\n
    Email: $email\n
    option1: $option1\n
    option2: $option2\n
    Message: \n
    $message
    "
    "From:" $email
    )
        {
        echo 
    "Your message was sent successfully!"
        }
    else
        {
        echo 
    "Something went wrong. Plese try again.";
        }
    ?>
    mail.html:

    Code:
    <html>
    
    <body>
    <p>
    	<form action='action.php' method='post'>
    	Name<input type='text' name='name' /><br>
    	Email<input type='text' name='email' /><br>	
    	Check all that apply:<br>
    	option1 <input name='option1' type='checkbox' /><br>
    	option2 <input name='option2' type='checkbox' /><br>
    	Message: <br>
    	<textarea name='message' rows='10' cols='40'>
    	</textarea><br>
    	<input type='submit' value='Submit' />
    </p>
    </body>
    
    </html>

  • Users who have thanked mvmacd for this post:

    cineweekly.com (11-15-2011)

  • #7
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    That seems to be working but how would I do the checkbox portion as an array instead of multiple variables? For example, some sites have shown naming all checkboxes the same and adding [] to the end. I did that but in the e-mail it just sends the word "Array". I think I'm just missing some PHP (not too familiar with it).

    Code:
    <input name='options[]' type='checkbox'  value='One' /><br>
    <input name='options[]' type='checkbox'  value='Two' />
    In this example, if both boxes were checked, I would expect the e-mail to read "One Two".

  • #8
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    I just replied to your PM with basically the same thing. To fix the Array problem just implode the array into your e-mail message string with ", " as the "glue" parameter and things should get back on track.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #9
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Rowsdower! View Post
    I just replied to your PM with basically the same thing. To fix the Array problem just implode the array into your e-mail message string with ", " as the "glue" parameter and things should get back on track.
    That's where I'm getting stuck, I can usually figure out form issues but PHP I simply don't know. I've tried playing with the implode code in the link you sent me but I just don't know enough about it. I don't know when to replace $array with $features or $features[] and when to leave the word "array" alone, etc. Thanks for the help so far. Soooo close.

  • #10
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    I'll grant you, I didn't test the script edit that I PM'd you, but I'm pretty sure it should have worked right out of the box. If not, what errors are you getting?
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #11
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    In the PM we changed the checkboxes names to features[] and when the form is submitted, I'm sent an e-mail with every other field being correct while the features checkboxes only says the word "Array" instead of the actual values that make up the array.
    Last edited by cineweekly.com; 11-16-2011 at 03:03 AM.

  • #12
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Google Forms

    Hi cineweekly.com,

    Rather than coding from scratch I recommend you use google forms. You can set it up to automatically email you and save the results into a spreadsheet that you can export into excel. It has a really easy form building interface and best of all it's free =)

    I have a tutorial here: http://www.jazzerup.com/blog/item/googleforms

    Jaz

  • #13
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    It's free but branded all over by Google. Thanks anyway. I'm going for a more professional look and we're literally a couple of lines of code away from what I need.

    EDIT: Hmmm, jazzerup, the more I look into your site the more I'm thinking you're here to sell stuff.
    Last edited by cineweekly.com; 11-16-2011 at 07:28 AM.

  • #14
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Above all post are very well structured but here i would like to suggest you that please Concentrate on Validation, if your Form have no validation then its worthless. Kindly add validation on Form.
    _________________________
    Open Source Web Developmet

  • #15
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by cineweekly.com View Post
    In the PM we changed the checkboxes names to features[] and when the form is submitted, I'm sent an e-mail with every other field being correct while the features checkboxes only says the word "Array" instead of the actual values that make up the array.
    The PM'd code also changed your line of code that populates the $message so that it implodes the array and separates the items with commas:

    PHP Code:
    $message="Title: $title \nURL: $url \nE-mail: $email \nDescription: $description \nGenre: $genre \nFeatures:\n ".implode(", ",$features)." \nUpdate: $update\n Age: $age \nMovies: $movies \nReference: $reference \nOther: $other"
    I believe that is the 15th line of code in your script.

    Did you update that line in your script as well? If so then there is no reason that the "Array" text should be plopped into the e-mail message.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    cineweekly.com (11-16-2011)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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