SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Submitting Multiple Values for Form Contol

    Is there a way to return multiple variables - associated with a Control - when a Form is submitted?

    Currently I have a Form with radio buttons like this...
    PHP Code:
        <!-- Set Radio Buttons -->
        <
    input id='Requestor" . $memberID . "_1' name='friendRequestDecision["
            . $memberID . "]' 
    type='radio' value='0' "
            . ((isset(
    $friendRequestDecision[$memberID]) && $friendRequestDecision[$memberID] == '0') ? "checked='checked'" : "")
            . 
    $disable . " />
        <
    label for='Requestor" . $memberID . "_1'>Decide Later</label

    It would make my life substantially easier if I could return both a $requestorID and $requesteeID - along with the value which equals $friendRequestDecision[$memberID]...

    Is this possible?

    Sincerely,


    Debbie

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    you do have two values: name => value so, you can also use the name as a value In your example, I can see $_POST['friendRequestDecision'] should be an array with defined keys.

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Yes.

    consider the following example

    Code:
    <input type="hidden" name="hiddenField" value="val1|val2|val3">
    note: using hidden input as an example but any form element would work.

    then explode()
    PHP Code:
    $var explode('|'$_POST['hiddenField']); 
    gives you the array of values.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Another idea:
    PHP Code:
    <?php
    $fieldValue 
    = array(
        
    'id' => 2,
        
    'name' => 'george',
    );
    ?>
    <input type="hidden" name="whatever" value="<?php echo base64_encode(serialize($fieldValue)) ?>" />
    .....
    as POST

    <?php

    $postedValue 
    unserialize(base64_decode($_POST['whatever']));

    ?>
    Now, as I can see the issue, you don't need all this things... you just need one value (ID or other thing) to keep a sync. Example:

    PHP Code:
    <?php
    $posibleValues 
    = array(
        
    => array( 'key1' => 'val1' ),
        
    => array( 'key2' => 'val2' ),
    );
    ?>
    <input type="hidden" name="whatever" value="2" />
    AND use
    <?php
    $value 
    = array();
    if( isset(
    $_POST['whatever']) ) {
        
    $value = isset($posibleValues[$_POST['whatever']]) ? $posibleValues[$_POST['whatever']] : array();
    }
    ?>

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Turns out I found another way to do things while I was waiting.

    Since I have things working the other way, and since I have 1,000 lines of tested, working code, I'm not too inclined to start "refactoring" just yet!!

    But if the swelling in my brain ever subsides, maybe I will re-open this thread and see if I can indeed do things a more efficient way?!

    Thanks for trying to help!


    Debbie


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
  •