SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: values in forms

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    values in forms

    Hi all,

    I am posting some values from a form into a second page. The values are displaying ok on the second page, whether i use echo or echo "<pre>" . print_r($_POST, 1) . "</pre>";.
    I am then saving these values in hidden fields in a form in the second page and posting them to another page. When i display the values on the third page (again whether using echo or print_r), any text after a white space does not appear. any ideas why?
    thanks

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Forgetting double quotes around the field values?

    Code php:
    echo '<input type="hidden" value='.htmlentities($_POST['f1']).' name="f1" />';
    should be:
    Code php:
    echo '<input type="hidden" value="'.htmlentities($_POST['f1']).'" name="f1" />';
    Saul

  3. #3
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you are passing a bunch of hidden values, start out with using an array to hold the variables...

    that way, you just pass the array over with a single HIDDEN line and not like multiple lines...
    leo d.

  4. #4
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would have to serialize the array and encode it with htmlspecialchars() in order to place the array in a single hidden field. A lot to go through, when you can just store the first submission in a session variable.

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Or

    http://us3.php.net/http_build_query
    http://us3.php.net/manual/en/function.parse-str.php

    PHP Code:
    <?php

    header
    ('content-type: text/plain');

    $a = array('milk''butter''eggs');
    $s http_build_query($a'list_''&amp;');

    print 
    '<input type="hidden" name="list" value="' $s .'">';

    print 
    "\n\n\n\n";

    parse_str(str_replace('&amp;''&'$s), $q);
    print_r($q);
    Return:
    Code:
    <input type="hidden" name="list" value="list_0=milk&amp;list_1=butter&amp;list_2=eggs">
    
    
    
    Array
    (
        [list_0] => milk
        [list_1] => butter
        [list_2] => eggs
    )
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •