473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

[RESOLVED] Select option text rather than option value

Hello everyone.

I am a real newbie to php, and this is my first attempt at writing anything.

I have created a Contact Form in html with a drop down selection box, which sends the completed form content to a different recipient depending on which option is selected in the drop down box.

All is working fine (much to my amazement and with a little help from others) EXCEPT, I am stuck with one part. When the form content is sent to the recipient, it shows the option value rather than the option text, and I cannot work my head around how to get it to show the text.

The relevant part of the Contact Form HTML code is:

Expand|Select|Wrap|Line Numbers
  1. <select name="Nature" size="1" id="Nature">
  2.             <option>Please Select</option>
  3. <option value="recipient_1">General Enquiries</option>          
  4. <option value="recipient_2">Hall Hire</option>
  5. <option value="recipient_3">Marquee Hire</option>
  6. <option value="recipient_4">Parish Church</option>
  7. <option value="recipient_5">Parish Council</option>
  8. <option value="recipient_6">Recreation Area</option>
  9. <option value="recipient_7">Other</option>
  10. </select>
and the PHP code is:

Expand|Select|Wrap|Line Numbers
  1.  /* Email Variables */
  2. $emailSubject = 'website_enquiry'; 
  3. $recipients = array(
  4.  
  5. 'recipient_1' => 'kim@example.com', 
  6. 'recipient_2' => 'kim2@example.com', 
  7. 'recipient_3' => 'kms3@example.com',
  8. 'recipient_4' => 'kim4@example.com',
  9. 'recipient_5' => 'kim5@example.com',
  10. 'recipient_6' => 'kim6@example.com',
  11. 'recipient_7' => 'kim7@example.com'
  12. );
  13.  
  14. $my_email = $recipients[$_POST['Nature']];
  15.  
  16.  
  17. /* Data Variables */
  18. $Name = $_POST['Name'];
  19. $Telephone = $_POST['Telephone'];
  20. $Email = $_POST['Email'];
  21. $Nature = $_POST['Nature'];
  22. $Questions = $_POST['Questions'];
  23.  
  24.  
  25. $body = <<<EOD
  26. <br><hr><br>
  27. Name: $Name <br>
  28. Telephone: $Telephone <br>
  29. Email: $Email <br>
  30. Nature: $Nature <br>
  31. Questions: $Questions <br>
  32. EOD;
  33. $headers = "From: $Email\r\n";
  34. $headers .= "Content-type: text/html\r\n";
  35. $success = mail($my_email, $emailSubject, $body,
  36. $headers);
So, basically, in the php above, within the 'body' i.e. the information being emailed, I have "Nature: $Nature", which returns the option value. I am trying to get it to return the option text itself to clarify the nature of the enquiry ( there are a couple of recipients who will receive emails for more than 1 type of enquiry and I need to show them which one it covers)Example: Assuming a user selects Hall Hire, it will currently send "recipient 2". I want it to send "Hall Hire" i.e the option text itself rather than the option value.

Is there a simple way of doing this ? Can anyone guide me please ?
Jul 3 '14 #1
2 1672
Dormilich
8,658 Expert Mod 8TB
When the form content is sent to the recipient, it shows the option value rather than the option text, and I cannot work my head around how to get it to show the text.
that’s simple: you can’t. the form will only transmit the assigned value (name-value pair), nothing else.

what you can do is putting the value of interest in the value attribute, i.e. if you need "Hall Hire" but not "recipient_2" just make "Hall Hire" the value.

another way were to use a data mapper (in this case a simple array would suffice) where you have the option’s value as array key and the option’s text as array value.
Jul 4 '14 #2
Doh !

Thanks Dormilich - couldn't see the wood for the trees when trying to protect the email addresses.

Have simply changed i.e. 'recipient_2' to 'Hall_Hire' in both html & php and it works perfectly.

Thanks so much.

Regards
Jul 4 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: melvynadam | last post by:
If I open a new page with very little text on it such as a bugmenot results page is there a way to select some of the text there and assign it to variables? Selecting all and copying to the...
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
1
by: BGS | last post by:
Is there some setting that will allow users to select the text displayed in a Label on a Windows Form? I would just like to be able to highlight the text so that I could use Ctrl-Ins to capture...
0
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
1
by: KwonNam Son | last post by:
Is this possible to align select box's option text? I tried <select style="text-align: center;"> and <option style="text-align: center;>text</option>, it didn't work properly. Any idea, please?...
3
by: cj | last post by:
When I select textbox1 I want all text in it to be selected. I used the textbox1_enter event to run textbox1.selectall() This works if I tab to the box but not if it is selected by clicking on...
3
by: ASP Developer | last post by:
I have a variety of pages that use a master page. For some reason when I attempt to copy any of the label text on the screen it seems to highlight most of the screen randomly and I can't simply...
2
by: Advo | last post by:
Having major issues with this simple task, and I cant work out why its not doing as it should/expected. Basically, ive got a drop down box with the added bit of php: <select name="title"...
5
by: =?Utf-8?B?bWNhdWxpZmZl?= | last post by:
I have an old application ( pre-VB5) that I need to add a select/option list to. This is an edit program so the values for the form will be retrieved from a database. How do I set the value of...
2
by: ahighfidelity | last post by:
Hi. I wonder if someone can help me. I have just recently finished our designing and building our company website... www.mediajunction.co.uk All appears fine when viewing it fully on Firefox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.