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…


	<!-- 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

you do have two values: name => value so, you can also use the name as a value :slight_smile: In your example, I can see $_POST[‘friendRequestDecision’] should be an array with defined keys.

Yes.

consider the following example


<input type="hidden" name="hiddenField" value="val1|val2|val3">

note: using hidden input as an example but any form element would work.

then explode()


$var = explode('|', $_POST['hiddenField']);

gives you the array of values.

Another idea:


<?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
$posibleValues = array(
    2 => array( 'key1' => 'val1' ),
    5 => 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();
}
?>

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!! :lol:

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