I am now using jquery .submit action (form) to POST the data. A normal POST operation in JAVA does not pass label/value key. For the following (sample) form how I do that ?. I do not want to use Ajax as my form would have upload file fields too and I know how to handle that only in simple POST operation.
<body>
<form id="frmRequest" name="frmRequest" >
<div class="clearfix" id="idRequestDetails" >
<table width="809" border="0" id="tbl_data_1_1_1_1__" summary="Profile">
<tr>
<th width="156" scope="col"><label class="labelrequest" for="txtProfileName1__">Name</label>
</th>
<th width="74" scope="col"><label class="labelrequest" for="txtProfileUserID1__">User ID</label></th>
<th width="131" scope="col"><label class="labelrequest" for="txtSiteCost1__">Site Cost Centre</label></th>
<th width="182" scope="col"><label class="labelrequest" for="txtDetail1__">Additional Details</label></th>
</tr>
<tr>
<td><input type="text" name="txtProfileName1__" id="txtProfileName1__" tabindex="100" /></td>
<td><input name="txtProfileUserID1__" type="text" class="clearfix" id="txtProfileUserID1__" tabindex="110" size="8" /></td>
<td><input name="txtSiteCost1__" type="text" id="txtSiteCost1__" tabindex="220" size="8" /></td>
<td><textarea name="txtDetail1__" rows="1" id="txtDetail1__" tabindex="240"></textarea></td>
</tr>
</table>
</div>
</body>
Tried the following but not working
foreach ($_POST as $key => $value)
{
if($key === 'labels') {
// Decode JSON string to array
$value = json_decode($value, true);
}
if (!is_array($value))
{
$message .= "<br/>".$key." : ".$value;
}
else
{
foreach ($value as $itemvalue)
{
$message .= "<br/>".$value." : ".$itemvalue;
}
}
}
You have to build inputs with information you need before form is sent.
Here is sample where I find text between LABEL tags.
Create hidden INPUT.
Set INPUT’s name.
Set INPUT’s value which is JSON encoded array of label values
Since I put all labels into JSON object, in foreach loop, before first if, you need to find labels data, decode it to array
Like this:
Just in case check out JSON functions and your PHP version