Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Trying to make our text fields in contact form REQUIRED! Frustrated!! PLEASE HELP!

  • This topic is empty.
Viewing 12 posts - 16 through 27 (of 27 total)
  • Author
    Posts
  • #119164
    __
    Participant

    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:

    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)

    #119173
    technosailor
    Member

    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

    #119213
    bkbillma
    Member

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

    #119221
    hendrix940
    Participant

    @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.

    #119222
    hendrix940
    Participant

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

    #119224
    bkbillma
    Member

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

    #119225
    hendrix940
    Participant

    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.

    #119272
    hendrix940
    Participant

    @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.

    #119273
    hendrix940
    Participant

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

    #119274
    __
    Participant

    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.

    #121583
    hendrix940
    Participant

    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.

    #121591
    hendrix940
    Participant

    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.