Results 1 to 8 of 8
  1. #1

    dumb php question help

    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.

  2. #2
    Join Date
    Nov 2005
    Location
    Buffalo
    Posts
    94

    Dumb Answer

    Quote Originally Posted by hoachen
    <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.

  3. #3
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    6

    easiest

    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>

  4. #4
    Join Date
    Mar 2004
    Posts
    1,301
    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

  5. #5
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    PHP Code:
    <?php

      $food_name 
    strtoupper(basename($_POST['Food'],'.htm')).' FOOD';
      echo 
    $food_name;

    ?>

  6. #6
    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.

  7. #7
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Well you have to edit it to suit your situation. I'll give you an example of what it will do here:

    PHP Code:
    $_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

  8. #8
    Join Date
    Mar 2004
    Posts
    1,301
    that's good to know- I haven't used basename() before. it really makes it simple.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •