[eluser]scoobie[/eluser]
thx for your suggestion ...
could i ask for further clarification / help ?
when i looked up user guide for set_value it gave an eg of ....
set_value()
Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function.
The second (optional) parameter allows you to set a default value for the form. Example:
<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
The above form will show "0" when loaded for the first time.
so i put this in the code=
Code:
printf('<input type="checkbox" name="%s[]" value="<?php echo set_value('%s[]', '0'); ?>" ', $name, $value, $label);
and gave an error of
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\application\views\account\main22.php on line 20
and then i changed it to
Code:
printf('<input type="checkbox" name="%s[]" value="<?php echo set_value('%s', '0'); ?>" ', $name, $value, $label);
and error is
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\application\views\account\main22.php on line 20
i'm not sure how to use this function properly (in fact the whole codeigniter i'm having trouble with, perhaps should have put 'newbie' in question),
could you please have a look
at the code below that will give you a working example of what i'm trying to achieve...may be easier ?
make a controller called hello.php
Code:
<?php
class Hello extends CI_Controller{
public function you()
{
$this->load->view('you_view');
}
}
?>
then in a view called 'you_view'
Code:
<title>Planets</title>
</head>
<body>
<?php
if( !isset($_POST['attributes'])) {
$attrs = array( );
$_POST['attributes']=$attrs;
}else{
$attrs = $_POST['attributes'];
}
if (! is_array($attrs)) { $attrs = array( ); }
function make_checkboxes ($name, $query, $options) {
foreach ($options as $value => $label) {
printf('<input type="checkbox" name="%s[]" value="%s" /> %s', $name, $value, $label);
if (in_array($value, $query)) { echo "checked "; }
// above line echo'es word "checked" instead of tick - not sure how to change the code so tickbox ticked ??
echo "<br />\n";
}
}
// the list of values and labels for the checkboxes
$planets = array(
'1' => 'Pluto',
'2' => 'Mars',
'3' => 'saturn',
'4' => 'Earth',
'6' => 'All Planets / All of the above'
);
?>
<form acti $_SERVER['PHP_SELF'] ?>" method="POST">
<b><u>STEP ONE</u></b> Select the Planets you want to see (Tick item/s below):<br /> <br /><br />
<?php make_checkboxes('attributes', $attrs, $planets); ?>
<br />
<input type="submit" id="submit" name="s" value="STEP TWO - See these Planets (CLICK here)" />
</form>
if you run this controller you'll see that the tickbox never gets reset to a checked state, but
the word 'checked' comes out next to tickbox once STEP TWO submit button is clicked
If you/ anyone knows how to fix this i'd relly appreciate the help - it's driving me mad! thanks.