I'm looking for a way to move the numeric values in an array collected using JQuery into a new array for Perl to pick up. Is this possible and is there a preferred method?
JQuery Array: addVssID
Hash array: $self->input->vssID
- addVssID has the values (1, 11, 25) to represent checkboxes that have been checked in an HTML form. This collection/calculation is triggered when a SAVE button is clicked.
- Elsewhere in the program $self->input has been newly created to hold various pieces of vendor information that Perl later processes and saves to a MySQL database. I'm tailing the values in a log file, and don't see my expected results when I use DUMPER($self) in my Perl, though I can see other values populated.
- I'm basically looking at existing legacy code, copy/edit it for my own needs, but it doesn't seem to be working.
Here is my JSON: To be completely honest, I don't really understand how this works.
var ShippingInput = $('<input type="hidden" name="Shipping" />');
$ShippingInput.val(JSON.stringify(getShipping()));
$form.append($ShippingInput);
On the other end in Perl, I have this waiting to catch the results:
my $Shipping = [];
eval { $Shipping = JSON::from_json($self->input->{'vendor'}->{'Shipping'});
};
Ultimately I want to move the array values into a MySQL table. The other option is to push the array into the MySQL table and pull it out into Perl for processing. I don't know if this changes anything, but we also have Template Toolkit available.
UPDATE/SOLUTION: Taking the JSON route, I took the dynamic value from the checkbox (value='Shipping_###'), strip off the text and add the number to array. I'm still shakey on how JSON/JQUERY works, but here is the get function and it seems to be working:
function getShipping() {
// called onSave from submitForm()
var shipping = [];
$('.Shipping').each(function(i, Shipping) {
shipping.push($(Shipping).attr('id').replace('Shipping_', ''));
});
return shipping;
}