hoachen
11-18-2005, 05:29 PM
I am doing a form that users fill in the form and submit it and this form will send to my email inbox. I have a problem on selection option on the form and php
for example html form will look like
<td width="44%" height="30"><select name="Food" size="1">
<option selected>Select One</option>
<option value="../food/western.htm" >Western Food</option>
<option value="../food/italian.htm" >Italian Food</option>
<option value="../food/western.htm" >Asian Food </option>
php code
$Message .= "Food: " . $_POST["food"] . "\n";
in my mailbox will look like this
Food: ../food/western.htm
HOW DO I GET RID OF THE ../FOOD/WESTERN.HTM AND JUST PRINT WESTERN FOOD?
I know it is easy for you as an expert but it is not easy for me. Please give you advise and opinion.
malenski
11-18-2005, 05:51 PM
<td width="44%" height="30"><select name="Food" size="1">
<option selected>Select One</option>
<option value="../food/western.htm" >Western Food</option>
<option value="../food/italian.htm" >Italian Food</option>
<option value="../food/western.htm" >Asian Food </option>
Should be
<td width="44%" height="30"><select name="Food" size="1">
<option selected>Select One</option>
<option value="Western Food" >Western Food</option>
<option value="Italian Food" >Italian Food</option>
<option value="Asian Food" >Asian Food </option>
Yes its a dumb answer - but you haven't said if you need the old values.
mmarinsen
11-18-2005, 06:53 PM
In fact, if you don't need the old values, then you could simplify even further. The text of the option (between the <OPTION> </option> tags) will become the default value if you don't specify a value inside <OPTION Value="HERE">.
So this would work, in theory:
<select name="Food" size="1">
<option selected>Select One</option>
<option>Western Food</option>
<option>Italian Food</option>
<option>Asian Food </option>
</select>
orbitz
11-18-2005, 07:00 PM
what if hoachen didn't want to change the value of those options?
- if that the case, then you can use regular expression method or str_replace to take out just the name of the file without the extension; then make the name with all capital letters; finally, concatinate it with the word "FOOD" --> and send to your email :)
Burhan
11-19-2005, 03:53 AM
<?php
$food_name = strtoupper(basename($_POST['Food'],'.htm')).' FOOD';
echo $food_name;
?>
hoachen
11-19-2005, 08:14 AM
orbitz is right I don't want to put value "option value=" here" is because, when i click on the selection it will bring me to another page. Yes, I only want it to send to my mail box not to echo. Orbitz, you suggested to put reg to trim it off but where(which part) i should do the reg? any suggestion?
I try it this way
$food = ._$POST['food'];
$new_food = ereg_replace("../food/*.htm", I don't know how to put here, $food));
$Message.= $new_food;
I just want to replace the "../food/.htm" where the *astrick is what i want to print it on my mailbox.
fyrestrtr, first thank you for your code, I try it and it didnt work. I don't want to echo anything and don't really understand what is "strtoupper(basename" Well, I will check it on the web later.
thank you guys for your suggestion.
Burhan
11-19-2005, 08:27 AM
Well you have to edit it to suit your situation. I'll give you an example of what it will do here:
$_POST['food'] = '../this/is/a/long/directory/to/show/you/how/it/works/apple.htm';
echo strtoupper(basename($_POST['food'],'.htm')).' FOOD';
You if you run that code, you will get as output :
APPLE FOOD
Look up the functions to see what they do. There really isn't any need to get involved in regular expressions for something as simple as this :)
orbitz
11-19-2005, 09:52 AM
that's good to know- I haven't used basename() before. :) it really makes it simple.
Thanks!