By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,644 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,644 IT Pros & Developers. It's quick & easy.

Modifying form data before submission

P: n/a
I have a form which houses basic inputs, as well as a few multiple select
forms.

I need to parse all the 'values' which are in this multiple select form (it
gets manipulated dynamically client side). I wanted to create a function
that loops through all the form elements, and if the type 'select-multiple'
is detected, gather the VALUES of each <option> inside it.

The bit I'm stuck on is then how to reconstruct this into a form submission.
Preferably I wanted the data from the 'select-multiple' element to be
submitted as comma delimited, eg 14,12,512,63,62 which would later be parsed
by PHP.

I was considering reconstructing a query string and submitting that as GET,
but I'd prefer to POST it along with the other data (such as INPUTS etc)
which do not need to be changed.

Can I somehow attach some 'hidden' type data onto the end of the form
submission at this point?

Thanks in advance
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 25 Jul 2003 17:43:45 +1000, "Logical" <lo***@privacy.net>
wrote:
I have a form which houses basic inputs, as well as a few multiple select
forms.

I need to parse all the 'values' which are in this multiple select form (it
gets manipulated dynamically client side). I wanted to create a function
that loops through all the form elements, and if the type 'select-multiple'
is detected, gather the VALUES of each <option> inside it.

The bit I'm stuck on is then how to reconstruct this into a form submission.
Preferably I wanted the data from the 'select-multiple' element to be
submitted as comma delimited, eg 14,12,512,63,62 which would later be parsed
by PHP.

I was considering reconstructing a query string and submitting that as GET,
but I'd prefer to POST it along with the other data (such as INPUTS etc)
which do not need to be changed.

Can I somehow attach some 'hidden' type data onto the end of the form
submission at this point?

Check the Netscape JavaScript site at http://devedge.netscape.com/
and look at the CFormData JAvaScript object.

That might do the trick for you.

Jul 20 '05 #2

P: n/a
First off, it's not really clear to me if you want the selected values from
a multiple select element, or just all of the values regardless of selection
state. In the case of the former (selected), you can just re-name your
multiple select element using this syntax:

<select name="manyselects[]" size="10" multiple="multiple">

That can be parsed/interpreted because it is already construed as an array
by PHP...

echo print_r($_POST['manyselects']);

In the case of the latter, you would have to implement a javascript
construct to loop through the select elements on the form before submittal
to collect the values. Perhaps something like the following...(untested)

The intention would be to get a comma separated string for all the
multiple-select option values. You could then perhaps assign that value to
a hidden form variable:
function processMultiples() {
var thisSelect;
var multiValues;
var theForm = window.document.forms[0];

for (var i = 0; i < theForm.length; i ++) {
if (theForm.elements[i].type == "select-multiple") {
thisSelect = theForm.elements[i];
for (var j = 0; j < thisSelect.length; j ++)
multiValues += thisSelect.options[j].value + ',';
}
}

// strip last comma
multiValues = multiValues.substr(0, multiValues.length - 1);

return multiValues;
}
--
HTH,
DWilliams

"Logical" <lo***@privacy.net> wrote in message
news:bf************@ID-159445.news.uni-berlin.de...
I have a form which houses basic inputs, as well as a few multiple select
forms.

I need to parse all the 'values' which are in this multiple select form (it gets manipulated dynamically client side). I wanted to create a function
that loops through all the form elements, and if the type 'select-multiple' is detected, gather the VALUES of each <option> inside it.

The bit I'm stuck on is then how to reconstruct this into a form submission. Preferably I wanted the data from the 'select-multiple' element to be
submitted as comma delimited, eg 14,12,512,63,62 which would later be parsed by PHP.

I was considering reconstructing a query string and submitting that as GET, but I'd prefer to POST it along with the other data (such as INPUTS etc)
which do not need to be changed.

Can I somehow attach some 'hidden' type data onto the end of the form
submission at this point?

Thanks in advance

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.