PHP form help

Hello all,

I have a form that uses POST to send the info to me. In the form, I have a drop down menu. I also have sub-menus that are visible or not based on which option is selected. For the sake of these sub-menus, I had to put a value to each option on the list so that I could use JS.

So here is the question: Is it possible to find a work around so that when the email is sent, the subject contains the item in the menu instead of its value and still be able to use the JS code?

Let me also note, that the code is working fine, so I only took out small portions for examples, I just want to get the subject part to look better for the sake of replies. Thank you so much in advance!!!

Lauren

Here is the html for the list:


<label for="subject">Subject:</label>
<select id="subject" name="subject" size="1">
<option>Select One</option>
<option value="gen">General Question/Comment</option>
<option value="video">Request an Audio/Video Quote</option>
<option value="bill">Payments/Billing</option>
<option value="comp">Computer Service</option>
<option value="mmserv">Multimedia Service</option>
<option value ="foren">Forensic Service</option>
<option value="other">Other</option>
</select>

here is the JS:


$('p#general').hide(); 
		$('#subject').change(function() {
        var val = $(this).val();
        var hide = (val == 'gen') ? false : true;
        (hide == true) ? $('p#general').slideUp('slow') : $('p#general').slideDown('slow');
		});

here is the php:



$msg = " Name: $name\
" .
	
	"Email:   $email\
" .
	
	"Phone:   $phone\
" .
	
	"$subject\
" .
	
	"Operating System:   $opsys\
" .
	
	"How did you hear about us?:   $hear\
" .
	
	"Promo Code:   $promo\
" .
	
	"Comments:   $description\
" . 
	
	"Join mailing list:   $mailing\
";

Not sure if this is what you mean, but you can have multiple values in the value of your select, I.E.


<option value="video|Request an Audio/Video Quote">Request an Audio/Video Quote</option>

After that you need one of the PHP list functions to use the second instead of the first value

You could use a different attribute to identify each option through JS; when the value attribute isn’t present, it sends the actual content of the option instead, so this would post “General Question” and be identifiable by the unique id optionGen.

<option id="optionGen">General Question</option>

Thanks so much for the quick responses guys!! All fixed!! You guys are awesome! Have a great night!!

Lauren :slight_smile:

Ok, i stand corrected. When I changed to using id instead of value, the submenus open when the item is selected, but do not hide again when a different one is picked. Am I not able to use the id attribute in the JS?

Time to try plan B.

Donboe, I don’t fully understand how to put multiple values in as far as the PHP and JS are concerned. is there a site that you could recommended to help me work through that? Also, if I use this, can I have the JS use the first, and the PHP use the second value?

Thanks!

Have you changed the JS to hide the menu based on ID instead of value?

Yes. Is this correct?



$('p#general').hide(); 
		$('#subject').change(function() {
        var val = $(this).val();
        var hide = ('#gen') ? false : true;
        (hide == true) ? $('p#general').slideUp('slow') :   $('p#general').slideDown('slow');
		});

I think I might have just found the mistake. I have

var val = $(this).val();

do I need to change to .val to something else?

On the upside, I think we’ve got the PHP part fixed :slight_smile:

(I’m not experienced in the slightest with jquery, so I’m hoping I’m on the right track here)

Oh you saw the problem! Yes, and I believe you need to use:

$(this).attr('id');

instead of

$(this).val();

and then you should be able to go back to the original (val == ‘gen’) to check it

Am I still using the var val? When I replace it like this it still won’t hide them again.


$('p#general').hide(); 
		$('#subject').change(function() {
        $(this).attr('id');
        var hide = ('#gen') ? false : true;
        (hide == true) ? $('p#general').slideUp('slow') : $('p#general').slideDown('slow');
		});

The idea was to be able to replace the value attribute with the id attribute right?

Also, if I don’t use value, and use id instead, will it effect this PHP?



if ($subject == 'video') {
	$msg = "  Name: $name\
" .
	
	"Email:   $email\
" .
	
	"Phone:   $phone\
" .
	
	"Subject:   $subject\
" .
	
	"Operating System:   $opsys\
" .
	
	"How did you hear about us?:   $hear\
" .
	
	"Promo Code:   $promo\
" .
	
	"Comments:   $description\
" . 
	
	"Join mailing list:   $mailing\
" .

	"No. of tapes:   $tapeQty\
"; 
	}

Thanks again! :slight_smile:

I also posted in the JS section, since that may be more the problem than the PHP. I don’t want to drive you completely crazy. I’ll keep on it and let you know how it goes :slight_smile: Thanks :slight_smile: