The below code is working great for handling errors for text fields in my contact form, but how do I get this same method to work for dropdown select option boxes and textareas?
<input type="text" name="name" value="<?php if($errors){echo $name;} ?>" id="name" size="30" />
For example:
<textarea name="message" value="<?php if($errors){echo $message;} ?>" id="message" rows="10" cols="40"></textarea>
does not work.
This is how you should do the INPUT: it’s like you have it, but you really should escape the user-provided content with htmlentities (or htmlspecialchars, etc.) in case they had quotes, brackets, etc. in the text that would be interpreted as HTML characters by the browser. That’s just good practice.
This is how you should do the TEXTAREA: put the content between the textarea open/close tags. And make sure to escape it properly too.
This is how you might handle the SELECT tag. I’ve spaced out the code for readability so you can understand what’s going on. Basically you just have to output
selected="selected"in the OPTION element you want to be selected.