473,657 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[RESOLVED] Select option text rather than option value

2 New Member
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 1689
Dormilich
8,658 Recognized Expert Moderator Expert
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
kimmcms
2 New Member
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
1698
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 clipboard can be done with: document.execCommand("SelectAll"); document.execCommand("Copy"); but I'm looking for something a little more refined. The page contains seven lines of text and I'd like a simple way to say:
4
4103
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 the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
1
4133
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 the text to the Windows clipboard. (I understand I could have the text display in a TextBox rather than a Label, but for various reasons, I would prefer a Label display, but one where the text could be copied). All help most appreciated. Bruce
0
2605
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 integers as input, limited by a ScrollBar's Minimum- and Maximum. Changing the ScrollBar-Value should update the Textbox-Text and vice versa. So the textbox-text and scrollbar-value represent the same value. The user is
1
34390
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? Regards, KwonNam.
3
2476
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 it. I hat to have to put textbox1.selectall() in the click event too. GotFocus event doesn't work any better than the enter event. I could swear that back in VB4 I used the gotfocus event to select all text no matter how the box was entered. ...
3
2385
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 copy the text. I can select all text that is inside a control such as a text box. It is only the labels that I can't get a hold of. Any suggestions would be greatly appreciated.
2
2122
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" id="title"> <?php if($_SESSION != "") { echo '<option value="'. $_SESSION .'"
5
13859
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 the dropdown with the value from the database. The value in the database is either new, trial, maint., employee, beta, or null. I need to set the dropdrown to one of these values. An example of the select; <td> <select name="ordReason">...
2
2009
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 and all IE web browsers. However, my boss has raised a couple of concerns which are driving me mad. The problem is, as you can see from the Page Source below, the main copy from each page appears via an iframe. Is there a way to make this text...
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.