Grow your CSS skills. Land your dream job.

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

  • # December 23, 2012 at 6:18 pm

    .

    # December 23, 2012 at 6:20 pm

    Here is the HTML:

    # December 23, 2012 at 6:26 pm

    Here is how I did it with js http://www.visibilityinherit.com/code/jquery-validation.php

    Here is how I did it with php http://www.visibilityinherit.com/code/php-form-validation.php

    Here is how @traq did it with php http://custom-anything.com/sand/contact_example.php

    # December 23, 2012 at 6:33 pm

    @eric, I have the code in place, I’m simply missing something small, I believe. Can you offer a shorter solution than editing all the above code to match mine? Thank you very much sir!

    # December 23, 2012 at 6:38 pm

    Sorry bud. Php is not my strong suit. I can’t just look at it and see the error. I’d have put it all together and test and stare at my desktop for many many minutes prob to fix. Someone else will swoop in and spot the error.

    # December 23, 2012 at 6:41 pm

    @eric, or anyone … If I’m using .PHP to submit a contact form, can I also use JS to validate the form?

    # December 23, 2012 at 6:45 pm

    You can js will prevent the form from being submitted until all required fields have been filled out correctly. Once it passes the js then it submits and php reads it. The way I do it is to simply have my js validation mirror my php validation. If you have js in place only 2% will ever need to be validated by the php.

    # December 23, 2012 at 6:46 pm

    The 2% that have js off

    # December 23, 2012 at 6:48 pm

    I’m in over my head with PHP and JS … I had a friend write this contact submit form code, and am lost!

    # December 23, 2012 at 6:50 pm

    So if you just want to throw some simple js validation in there until you get the php working then use this – take you 2 seconds. http://www.visibilityinherit.com/code/js-form-validation.php

    # December 23, 2012 at 6:52 pm

    Okay, I will try this @eric, thank you. To be clear, will I still be using the PHP to send the form to the email address? This new line of JS will work hand in hand with the PHP, correct? My above PHP code does work, but it just won’t make the fields REQUIRED. Will the above JS make the fields REQUIRED? Thank you sir!

    # December 23, 2012 at 6:56 pm

    Everything you said is spot on. Nothing will change with the way it currently works. But you will eventually want to get some php validation in there. Spambots could use your form for all kinds of spammy things.

    But oh it works you just need that one thing? Someone will write hat for you in two secs

    # December 23, 2012 at 6:59 pm

    Okay, so then I’ll please wait if someone else can offer a resolution! Thanks @eric. Anyone if you have way to add just this one tweak, PLEASE HELP!

    # December 24, 2012 at 2:17 am

    @hendrix – I don’t see any of your code?

    However, I will say this:

    You need to consider that **javascript is not secure**. JavaScript validation is great for the user – to make their experience using your form happier – but it is **not** a replacement for server-side validation. JS can be turned off. JS can be manipulated. It is under the complete control of the user, and therefore, *cannot be trusted*.

    Server-side validation is **always necessary**.

    Also,

    > This new line of JS will work hand in hand with the PHP, correct?

    **Edit**: I may have misunderstood your question, here. No, they don’t work together (i.e., they don’t *interact*), but you may have been asking if they would *conflict* with each other? If so, that’s unlikely. **/edit**

    No. Javascript and PHP cannot “work together.” They don’t run at the same time, or even on the same computer:

    …PHP runs *first*, **on your server**. When it’s done, it sends its output (typically HTML markup + JavaScript code) to the user’s browser. **Then it stops**.

    …JavaScript runs *later*, **on the user’s computer**. It has *no clue* that PHP ever existed.

    *****
    If you’re still trying to figure this out, please point me to your code, and I’d be happy to help.

    # December 24, 2012 at 11:43 am

    @traq, thank you very much for your detailed explanation. Please, remind me the best way to get all the code to you for examination? I believe you suggested GitHub?

Viewing 15 posts - 1 through 15 (of 37 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".