I'm trying to post input using form but there are a looping for id (parameter) on anchor. And here I got the problem that param embedded on anchor should post too directly when I clicked
much tips I have tried, more of them not work, 2 options seem good forward but not properly I looking for
Option 1
$attributes = array('name' => 'myForm', 'id' => 'form_id');
echo form_open_multipart('needs/add_items', $attributes);
?>
<?php foreach ($models as $model) : ?>
<input type="hidden" name="<?php echo $model['model'];?>" value="<?php echo $model['model'];?>">
<a href="#<?php echo $model['model'];?>" onclick="document.myForm.<?php echo $model['model'];?>.value; document.myForm.submit(); return true"><?php echo $model['model'];?></a><br>
<?php endforeach;?>
</form>
Result:
{..["Eiger"]=> string(5) "Eiger" ["Kalibre"]=> string(7) "Kalibre" ["Forester"]=> string(8) "Forester" ["UNIX_Glove"]=> string(10) "UNIX Glove" ["UNIX_Masker"]=> string(11) "UNIX Masker" ["Neoprene"]=> string(8) "Neoprene" }
Option 2
$attributes = array('name' => 'myForm', 'id' => 'form_id');
echo form_open_multipart('needs/add_items', $attributes);
?>
<?php foreach ($models as $model) : ?>
<input type="hidden" name="model" value="">
<a href="#<?php echo $model['model'];?>" onclick="document.myForm.model.value='<?php echo $model['model'];?>'; document.myForm.submit(); return true"><?php echo $model['model'];?></a><br>
<?php endforeach;?>
</form>
Result:
{..["model"]=> string(0) ""..}
I expect the output just
{["Eiger"]=> string(5) "Eiger" }
when I just clicked anchor contains model Eiger