SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Divisive Cotton's Avatar
    Join Date
    Jun 2008
    Location
    Andy lives in London, UK
    Posts
    393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick question on making sticky form values when form uses arays in values

    Here is my form:

    Code:
    <label for="aId">This is an input box</label><input type="text" value="  " maxlength="40" class="aClass" id="aId" name="affiliate_hoover_plugin_options[aName]"/>
    And this is what the the $_POST looks like after submission:

    Code:
    Array
    (
        [affiliate_hoover_plugin_options] => Array
            (
                [aName] =>   Here is a value
            )
    )
    The trouble comes when I'm trying get the code right for a sticky value in another function

    As expected this works great if an array isn't used:

    PHP Code:
    isset($_POST[$name]) ? print $_POST[$name] : null
    So my initial thought was that this would work with arrays, but it doesn't:

    PHP Code:
    isset($_POST[$option_name[$name]]) ? print $_POST[$option_name[$name]] : null
    I've tried different variations but the damn value isn't sticking after submission
    Let everyday be Christmas

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You can simply print $_POST[$option_name[$name]], there's no need to a ternary operator. If there's nothing in that variable, it will echo nothing anyway.

    I also don't understand your usage of the term "sticky."

    However, the code you presented is valid and works fine with arrays, so it's not the syntax that's the problem.


Bookmarks

Posting Permissions

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