Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    76
    Thanks
    19
    Thanked 1 Time in 1 Post

    Issue with variables

    I don't really know how to describe this issue but I'll do my best...

    I'm trying to create a function that will automatically render HTML input forms. Everything works great except one little issue which I'll give an example of.

    Basically I want to be able to feed in an array of field name pairs into a function to duplicate a form field like this:

    Code:
    First Name <input type="text" name="first_name" value="<?php echo $first_name; ?>" />
    So here's what I came up with:

    PHP Code:
    $fields = array('First Name'=>'first_name''Last Name'=>'last_name');
    renderForm($fields); 
    and then the function to render the form is basically like this:

    PHP Code:
    renderForm($_fields) {
    foreach(
    $_fields as $_field_name => $_value) {
    echo 
    $_field_name ' <input type="text" name="' $_value '" value="" />';
    }

    My issue is how to display the value variable, which should be the name of the form field so once the form is submitted, if there are any errors then the values of the form fields will populate the fields. But with this function I'm trying to do, I don't see how this can be done.
    Last edited by cgdtalent; 05-11-2013 at 11:24 PM.

  • #2
    Regular Coder
    Join Date
    Dec 2011
    Posts
    103
    Thanks
    5
    Thanked 17 Times in 17 Posts
    OOPs... I didn't see you were trying to get a value from a form...sorry me bad. I'll get back to you (that is if someone else doesn't beat me to the punch )
    Last edited by Strider64; 05-11-2013 at 11:24 PM.

  • #3
    New Coder
    Join Date
    Jan 2013
    Posts
    76
    Thanks
    19
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Strider64 View Post
    OOPs... I didn't see you were trying to get a value from a form...sorry me bad. I'll get back to you (that is if someone else doesn't beat me to the punch )
    Ok thanks.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Since its in a function, you can find it under $GLOBALS[$_value]. Alternatively, you can restructure the input array to have all information it requires (recommended since globals are a pain to debug).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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