Jump to content

Webmail - using drop-down for subject


murfitUK

Recommended Posts

OK. I'll try my best to describe what I'm trying to do.I have a webpage through which a user can send an email. They type in their name, email address, a subject and the message then click Send. The page then calls itself, checks that none of the four fields are empty and that the email address is a valid address. If everything is OK, the email gets sent.If anything is missing the page is displayed again along with everything the user typed so that they don't have to type it all again. (You can see what it's like at www.wooden-heart.co.uk - in the Contact Us section.)Anyway, what I'd like to do is limit the subject field to a few items from a drop-down list. This works but if the page is recalled, it does not keep the subject chosen by the user - it always displays the top item. I would like it to keep what the user has already chosen, but don't know how.Here's some of the code.BEFORE (when user types subject):echo "<input type='text' name='subject' value=\"" . $_POST['subject'] . "\" />\n";The . $_POST['subject'] . bit makes sure that the user's typed field gets added to the value of subject field so the user doesn't need to type it again if the page is recalled.AFTER (when user has to choose from drop-down list):echo "<select name='subject'>\n<option value='Sales Enquiry'>Sales Enquiry</option>\n<option value='Comment About Website'>Comment About Website</option>\n<option value='Other Enquiry'>Other Enquiry</option>\n (& there will be a few more options)</select>\n";I know I can use selected='selected' to make one of the options be selected but I'm not sure what I have to do. I think I will have to put an if... in each of the option value lines. Something like:echo "<option value='Sales Enquiry' "; if ($_POST['subject']=="Sales Enquiry") echo "selected='selected'"; print ">Sales Enquiry</option>";for each line obviously changing Sales Enquiry to the relevant text.Am I on the right track? Is there an easier way to do it?Thanks.

Link to comment
Share on other sites

OK. I'll try my best to describe what I'm trying to do.I have a webpage through which a user can send an email. They type in their name, email address, a subject and the message then click Send. The page then calls itself, checks that none of the four fields are empty and that the email address is a valid address. If everything is OK, the email gets sent.If anything is missing the page is displayed again along with everything the user typed so that they don't have to type it all again. (You can see what it's like at www.wooden-heart.co.uk - in the Contact Us section.)Anyway, what I'd like to do is limit the subject field to a few items from a drop-down list. This works but if the page is recalled, it does not keep the subject chosen by the user - it always displays the top item. I would like it to keep what the user has already chosen, but don't know how.Here's some of the code.BEFORE (when user types subject):echo "<input type='text' name='subject' value=\"" . $_POST['subject'] . "\" />\n";The . $_POST['subject'] . bit makes sure that the user's typed field gets added to the value of subject field so the user doesn't need to type it again if the page is recalled.AFTER (when user has to choose from drop-down list):echo "<select name='subject'>\n<option value='Sales Enquiry'>Sales Enquiry</option>\n<option value='Comment About Website'>Comment About Website</option>\n<option value='Other Enquiry'>Other Enquiry</option>\n (& there will be a few more options)</select>\n";I know I can use selected='selected' to make one of the options be selected but I'm not sure what I have to do. I think I will have to put an if... in each of the option value lines. Something like:echo "<option value='Sales Enquiry' "; if ($_POST['subject']=="Sales Enquiry") echo "selected='selected'"; print ">Sales Enquiry</option>";for each line obviously changing Sales Enquiry to the relevant text.Am I on the right track? Is there an easier way to do it?Thanks.
y dont u try cookies
Link to comment
Share on other sites

Store the labels as an array, then loop through the array, adding the selected=selected to the printed line if conditon is true for the comparison of the $_POST['subject'] value and the array element. Check to see if there is a value in the $_POST['subject'] before the comparison loop, or by using an isset(), and handle accordingly.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...