Home › Forums › CSS › Trying to make our text fields in contact form REQUIRED! Frustrated!! PLEASE HELP!
- This topic is empty.
-
AuthorPosts
-
December 27, 2012 at 9:15 pm #119164
__
ParticipantWhat 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)
December 28, 2012 at 12:02 am #119173technosailor
MemberYou 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 #119213bkbillma
MemberNot 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 #119221hendrix940
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.
December 28, 2012 at 1:46 pm #119222hendrix940
Participant@traq, yes currently the form HTML and the PHP are on separate pages.
December 28, 2012 at 1:47 pm #119224bkbillma
Memberit 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 #119225hendrix940
ParticipantOkay 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 #119272hendrix940
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.
December 28, 2012 at 10:49 pm #119273hendrix940
ParticipantI appreciate the guidance, I am an extreme novice with php.
December 28, 2012 at 11:06 pm #119274__
ParticipantYes; 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 #121583hendrix940
ParticipantGuys, 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 #121591hendrix940
ParticipantOkay, 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.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.