SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Function Help

  1. #1
    SitePoint Member cschoon's Avatar
    Join Date
    Dec 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function Help

    Hello,

    I have a radio function I created.
    <?php
    function questionnaire($name, $choices, $q)
    {
    // setting up the select option
    foreach ($choices as $c):
    $radioSelected = ($c == $q ? 'checked="checked"' : "");
    $radio .=<<<EOD
    <input name="$name" type="radio" value="$c" />
    <input name="work" type="hidden" value="testing" />
    EOD;
    endforeach;
    return $radio;
    }
    ?>
    $choices = Array("items1", items2", etcc..);
    I call it like $trac = questionnaire("Tracheostomy", $choices, $row_nameInformation['Tracheostomy']);
    When I preview the source on the page the html rendered looks correctly.

    But when I post to an update_Page.php I can't get the post to work. When I check for $name or the hidden "work" as a test it comes up blank each time. I have a dropdown select menu, a yes no menu which I have set up functions the same way and they all work.

    Any help as to what I am missing with the radio?/
    Thanks

  2. #2
    SitePoint Member cschoon's Avatar
    Join Date
    Dec 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it thanks.

  3. #3
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it, but can you post what you found, so that others might learn?
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  4. #4
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cschoon View Post
    I got it thanks.
    Glad that you got it.
    But the way you presented your problem is poor. Hope you can present your solution in a neater way

  5. #5
    SitePoint Member cschoon's Avatar
    Join Date
    Dec 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dave Morton View Post
    Glad you got it, but can you post what you found, so that others might learn?
    Well I was hoping to just delete the thread because the function was working I just forgot to put inside the form. So naturally when I hit submit it would make sense nothing would post. So if someone comes across this post looking for a function for multiple radio button(s), it works just put inside the form. Have a good laugh



    Function
    <?php
    function questionnaire($name, $choices, $q)
    {
    // setting up the select option
    foreach ($choices as $c):
    $radioSelected = ($c == $q ? 'checked="checked"' : "");
    $radio .=<<<EOD
    <input name="$name" type="radio" value="$c" />
    <input name="work" type="hidden" value="testing" />
    EOD;
    endforeach;
    return $radio;
    }
    ?>

    How use it in php page:
    $var = questionnaire("Tracheostomy", $var(this one is an array for me), $var);


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
  •