I have custom page template. In this template have a html table with radio button in each table row. I tried to retrieve the value of radio button from MYSQl but I have no luck.
Scenario: If the user choose "Yes" option, the table row will be disabled. Now, the value of radio button is retrieve but not the disabled featured of "Yes" option.
How to fix this?
PHP UPDATED
if (isset($_POST['list_location']) && $_POST['list_location'] != 'Select by Location'){
$list_location = $_POST['list_location'];
$result_location = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT id, submit_time, last_name, first_name, middle_name, mobile_number, email, location, position, message, attachment_resume_id, process_resume FROM resume_databank WHERE location = '" . $list_location . "' ORDER BY location ASC", OBJECT));
echo '<table>';
echo '<tr>';
$optionId = 0;
echo '<th>Submit Time</th>';
echo '<th>Last Name</th>';
echo '<th>First Name</th>';
echo '<th>Middle Name</th>';
echo '<th>Mobile Number</th>';
echo '<th>Email</th>';
echo '<th>Location</th>';
echo '<th>Position</th>';
echo '<th>Message</th>';
echo '<th>Resume</th>';
echo '<th>Processed?</th>';
for ($i=0;$i < count($result_location); $i++){
$row = $result_location[$i];
$optionId = $result_location[$i]->id;
$checkYes = "";
$checkNo = "";
if($result_location[$i]->process_resume == "Yes"){
$checkYes = "checked";
}
if($result_location[$i]->process_resume == "No"){
$checkNo = "checked";
}
echo '<tr>';
echo '<td id="submit_time">' . $result_location[$i]->submit_time . '</td>';
echo '<td id="last_name">' . $result_location[$i]->last_name . '</td>';
echo '<td id="first_name">' . $result_location[$i]->first_name . '</td>';
echo '<td id="middle_name">' . $result_location[$i]->middle_name . '</td>';
echo '<td id="mobile_number">' . $result_location[$i]->mobile_number . '</td>';
echo '<td id="email">' . $result_location[$i]->email . '</td>';
echo '<td id="location">' . $result_location[$i]->location . '</td>';
echo '<td id="position">' . $result_location[$i]->position . '</td>';
echo '<td id="message">' . $result_location[$i]->message . '</td>';
echo '<td id="resumeFile'.$optionId.'"><a href=' . wp_get_attachment_url($result_location[$i]->attachment_resume_id) . '>Download Resume</a></td>';
echo '<td id="radioOption><label for="Yes">Yes</label>
<input type="radio" id="processedOptionYes'.$optionId.'" name="processedOption'.$optionId.'" ' . $checkYes . ' value="Yes" onclick="proccessedCheck('.$optionId.',\'Yes\')"/>
<label for="No">No</label>
<input type="radio" id="processedOptionNo'.$optionId.'" name="processedOption'.$optionId.'" ' . $checkNo . ' value="No" onclick="proccessedCheck('.$optionId.',\'No\')"/></td>';
echo '</tr>';
}
echo '</table>';
}
JS:
function proccessedCheck(optionId,optionAnswer){
if(optionAnswer == 'Yes'){
if (confirm('You have chosen ' + optionAnswer + ', is this correct?')){
jQuery("#processedOptionYes" + optionId).attr('disabled',true);
jQuery("#processedOptionNo" + optionId).attr('disabled',true);
var withlink = jQuery("#resumeFile"+ optionId).html();
var withoutlink = jQuery(withlink).html();
jQuery("#resumeFile"+optionId).html("").append(withoutlink);
jQuery("#inputHidden1").val(optionId);
jQuery("#inputHidden2").val(optionAnswer);
jQuery("#hiddenForm").submit();
}
}
}
Hidden form and PHP:
<?php
if (isset($_POST['optionAnswer']) && $_POST['optionAnswer']){
$optionId = $_POST['optionId'];
$optionAnswer = $_POST['optionAnswer'];
$queryOptionId = $wpdb->query($wpdb->prepare("UPDATE resume_databank SET process_resume = '$optionAnswer' WHERE id = %d", $optionId));
}
?>
<form id='hiddenForm' method='POST' action=''>
<input type="hidden" id="inputHidden1" name="optionId" />
<input type="hidden" id="inputHidden2" name="optionAnswer" />
</form>