I'm developing a small webpage that reads data from a couple of files and render it into a website. In that website, user must be able to choose one or more items and perform some work with those (changing name, append values, etc). I've been able to do most of the work, but now I'm facing a problem. I have this form:
<div id="inside">
% foreach my $value ( @{ stash('tagitems') } ) {
<div id="inside">
%= form_for 'save' => begin
<input type="radio" name="radioid">
%= hidden_field 'id' => $indexnum
%= input_tag 'tag', value=>"$value", size=>"50%"
%= submit_button 'Save changes'
<%= select_field 'levelSelected' => [ @{ stash('levelsArray') }] %>
<button type="submit" form="insertForm">Insert</button>
% end
<form action="/insert" id="insertForm"></form>
</div>
% $indexnum += 1;
% }
I'm getting everything rendered and it's ok. I can use the save form (that routes to a sub that changes it's name. the problem is with the inserform. The insert is supposed to check every radio button that it's checked and take the value tag and levelSelected.
How can I do this?
Thanks.
Edit:
I've multiple instances that looks like this:
So, I need to have just one insert button (instead of one per item) that find out whatever radio button is checked and get info of all checked items (tag and levelSelected) when clicked the submit button.
EDIT2 - CODE THAT WORKS: I've found a way to do it. The code is here:
%= form_for 'save' => begin
<button type="submit" formaction="insert">Insert</button>
% foreach my $value ( @{ stash('tagitems') } ) {
<div id="inside">
<input type="checkbox" name="insert">
%= hidden_field 'id' => $indexnum
%= input_tag 'tag', value=>"$value", size=>"50%"
<button type="submit" formaction="save">save</button>
<%= select_field 'levelSelected' => [ @{ stash('levelsArray') }] %>
</div>
% }
% end
</form>
This can be done using this piece of code:
Then, in the controller: