Welcome Guest, Not a member yet? Register   Sign In
set_value() and input names that are arrays.
#3

[eluser]aquary[/eluser]
EDIT: Just realized the topic was almost a year...10 minutes waste LOL

I'll left the comment here anyway .-.


Cannot remember what is exactly inside the set_value.... but,

Code:
I find it odd that the set_value method that is in the Form validation library uses array_shift() to return the first value in the array, and any other elements of the array are unusable. What is the reason for this?

It's not unsable, all the remains data is still there inside the function (what did PHP call.... static, maybe?). So the next time set_value() or whatever got called, the next value will be fetched out.

Also, you are using an odd way to repopulate the checkboxes, especially the checked part. You know you could use set_checkbox() ?

Code:
// As in the userguide
<input type="checkbox" name="mycheck[]" value="1" <?php echo set_checkbox('mycheck[]', '1'); ?> />
<input type="checkbox" name="mycheck[]" value="2" <?php echo set_checkbox('mycheck[]', '2'); ?> />

// in your case... , never used the form_checkbox before, but let see.
<input type="checkbox" name="checkboxes" id="checkbox_one" value="one" <?=set_checkbox('checkboxes[]', 'one');?>
?>

And the first part of your code, I assume it's data from database or so, for editting. Now trying to put a default value...
Code:
<?
  // no need to call set_value here
  $values=isset($personal_data->checkboxes)?unserialize($personal_data->checkboxes) : array();
  $checkbox_data = array(
    'name'        => 'checkboxes[]',
    'id'        => 'checkbox_one',
    'value'        => 'one',
    // Here, the checked required TRUE/FALSE, not string of checked
    'checked'    => in_array('one', $submission_values),
    'class'        => 'form_checkbox'
  );
   echo form_checkbox($checkbox_data);
?>

Try it, let see what will you got.

One more thing, what was the validation rules you set for the checkboxes?

Lastly, before trying, please revert/removed the changes stuff you did in the last 2 code box, to be sure are using the same script with the userguide. Smile


Messages In This Thread
set_value() and input names that are arrays. - by El Forum - 03-27-2011, 08:47 PM
set_value() and input names that are arrays. - by El Forum - 02-23-2012, 07:56 AM
set_value() and input names that are arrays. - by El Forum - 02-23-2012, 08:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB