Give help. Get help.

  • __
    # December 27, 2012 at 9:15 pm

    What errors are you getting? If they’re “undefined index” errors, it’s not what I added – it’s because you don’t check if the form was submitted before trying to use it.

    To explain, for example:

    $name = trim(strip_tags($_POST));

    if the form was submitted, then `$_POST` will hold the value that the user entered. However, if the form was *not* submitted, then `$_POST` won’t even *exist*, so you get an error.

    I suspect you had the HTML form and the PHP processing script on separate pages before(?), so you wouldn’t have noticed. It would have still been a problem, though (for example, if the user didn’t fill out one of those fields).

    Try a structure like this:

    < ?php /* if $_POST is empty,
    the form was not submitted. */
    if( !empty( $_POST ) ){

    /* form was submitted
    validation code goes here */
    /* don’t forget to set $error
    if something is invalid */

    if( empty( $error ) ){

    /* all fields valid
    code to send email goes here */

    /* here, you could put an else{} block
    for error handling/messages */


    Also, please note I only wrote a check for one field (as an example; you can check the other fields similarly)

    # December 28, 2012 at 12:02 am

    You must do server side validation for true security. The folks above are helping on that. But if you’re using HTML5, you can just also add the required attribute to your inputs

    # December 28, 2012 at 1:09 pm

    Not sure where this stands currently. Just trying to catch up but it looks like it is close to complete.

    # December 28, 2012 at 1:45 pm

    @bkbillma, I’m going to test the code that @traq submitted above tonight. @technosailor, I’m not sure if it’s HTML5 or not. I posted the code above in a GIST link.

    # December 28, 2012 at 1:46 pm

    @traq, yes currently the form HTML and the PHP are on separate pages.

    # December 28, 2012 at 1:47 pm

    it is not HTML5 but it doesn’t really matter as the HTML5 form support is severely lacking right now

    # December 28, 2012 at 1:50 pm

    Okay very good, thank you @bkmillma. Yes I will move forward with the code @traq suggested this evening. I will post results. Thank you all.

    # December 28, 2012 at 10:45 pm

    @traq, yes thank you, I currently have the form on one page, then people click ‘SEND’ and the .php is on another page. In your code above, all the html AND php go on the contact page? Correct? Thank you.

    # December 28, 2012 at 10:49 pm

    I appreciate the guidance, I am an extreme novice with php.

    # December 28, 2012 at 11:06 pm

    Yes; though it’s easier to write reusable code if it’s in a separate file.

    For what you’re doing, it’s not a critical issue. Do whatever makes most sense to you.

    # January 20, 2013 at 10:29 am

    Guys, I appreciate all the help. But my rookie PHP skills aren’t at this time adequate for me to understand an implement this solution. I will try it again later when I have more time to put into this. @traq, thank you sir very much for all your help. Perhaps in the future you will be able to assist in other problems I have. Thank you.

    # January 20, 2013 at 12:14 pm

    Okay, thank you @Eric. With the above code, will I have to recreate my current forms or .PHP fields? I will follow through your above tutorial. Thank you again.

Viewing 12 posts - 16 through 27 (of 27 total)

You must be logged in to reply to this topic.