So, I have a html.php page with three buttons: "Clear Page", "Restore" and "Refresh Information".
When the user first opens the form, he is empty, and they can either enter the id = "siteId" value or the id = "siteName" value, and then click the "Get" button to request the rest of the saved information about the site from the mySQL database and is displayed in the shape of.
If the user wants to change / update any of the details, he can do it in the same form, and then click the "Update information" button to return the site data back to the database.
All (somewhat) is good so far. But when the "Update Information" button is clicked after successfully displaying information about the site (after the site data has been received from the database), any logical data represented by the switches is returned as the array of current values onobserved using print_ron on.
For each of the php switches, the legend is used in the line with html to determine what radio button should be checkedfor each line / field after extracting data from the database. Maybe that's why the form somehow sets the value onfor all switches when you click the Update button instead of previously defined logical values?
If so, what correction can there be, since I need to check with the help of conventions, which switch for any given set should be checked?
Screenshot of the html.php page:
}
?>
<h1 id="heading">Cell Site Details</h1>
<!--fieldset id="Site:"-->
<!--legend>Site:</legend-->
<div id="formContentDiv">
<form id="formContent" action="#" method="post" accept-charset="utf-8">
<input type="hidden" name="submitted" value="true">
<div id="clearPageDiv">
<a href="index2.php">
<input type="button" id="buttonClear" name="clearPage" class="button" value="Clear Page">
</a>
</div><!-- closes clearPageDiv -->
<div id="retreiveDiv">
<input type="submit" id="buttonRetreive" name="retreive" class="button" value="Retreive">
</div><!-- closes retreiveDiv -->
<div id="updateDiv">
<input type="submit" id="buttonUpdate" name="update" class="button" value="Update Details">
</div><!-- closes updateDiv -->
<div class="formRowDiv">
<label>
<span>Site Id:</span>
<input type="text" id="siteId" name="siteId" class="textInputShort" maxlength="" $value="">
<script>
siteId.value = <?php echo json_encode( ucfirst( $siteId ) ); ?>;
</script>
</label>
</div>
<div class="formRowDiv">
<label>
<span>Site Name:</span>
<input type="text" id="siteName" name="siteName" class="textInput" maxlength="" $value="test">
<!--input type="submit" value="Retreive"-->
<script>
siteName.value = <?php echo json_encode( ucwords( $siteName ) ); ?>;
</script>
</label>
</div>
<div class="formRowDiv">
<label>
<span># HSPA BBUs:</span>
<input type="text" id="numHspaBbu" name="numHspaBbu" class="textInputShort" maxlength="" $value="">
<script>
numHspaBbu.value = <?php echo json_encode( $numHspaBbu ); ?>;
</script>
</label>
</div>
<div class="formRowDiv">
<label>
<span># LTE BBUs:</span>
<input type="text" id="numLteBbu" name="numLteBbu" class="textInputShort" maxlength="" $value="">
<script>
numLteBbu.value = <?php echo json_encode( $numLteBbu ); ?>;
</script>
</label>
</div>
<div class="formRowDiv">
<label><span>Ext. Alarm Terminations:</span></label>
<label>
<input type="radio" name="extAlarmsTerminated"
<?php
if ( $extAlarmsTerminated == "hspa" ) {
echo 'checked';
}
?>
>
<span>HSPA</span>
</label>
<label>
<input type="radio" name="extAlarmsTerminated"
<?php
if ( $extAlarmsTerminated == "lte" ) {
echo 'checked';
}
?>
>
<span>LTE</span>
</label>
<label>
<input type="radio" name="extAlarmsTerminated"
<?php
if ( $extAlarmsTerminated == "hspa-lte" ) {
echo 'checked';
}
?>
>
<span>HSPA-and-LTE</span>
</label>
</label>
</div><!-- close formRowDiv -->
var $ extAlarmsTerminated is one of these switch groups in the following array of site details:
$inputVals = array( $siteId, $siteName, $numHspaBbu, $numLteBbu, $extAlarmsTerminated );
print_r( $inputVals );
print_r output showing first the value of the Boolean switch displayed after the user presses the Search button:
Array ( [0] => P6969 [1] => Toledo Centre [2] => 1 [3] => 1 [4] => hspa-lte
print_r an output showing the value of the switch for the same parts of the site after the user clicks the "Update Information" button:
Array ( [0] => P6969 [1] => Toledo Centre [2] => 1 [3] => 1 [4] => on )
EDIT:
I assigned each of the input field values obtained from the database to PHP $ _SESSION var, and when the "Update Details" button is clicked, they refer to the $ _SESSION vases that solved the original problem with the switches on.
, . JS/AJAX , JS, , , . , :
<div class="formRowDiv">
<label>
<span>Site Name:</span>
<input type="text" id="siteName" name="siteName" class="textInput" maxlength="" $value="test">
<script>
siteName.value = <?php echo json_encode( ucwords( $siteName ) ); ?>;
</script>
</label>
</div>
<script>
$( document ).ready( function() {
$( "#siteName" ).on( 'change', function() {
var siteName = document.getElementById( 'siteName' ).value;
$.ajax ({
url: 'ajax.php',
data: { siteName : siteName },
success: function( result ) {
alert( 'Site Name value changed to: ' + siteName );
}
});
});
});
</script>
, JS, $siteName, . ajax.php, , :
<?php
echo ( $_GET[ 'siteName' ] );
?>
, $siteName - :
$siteName = $_GET[ 'siteName' ];
, , . PHP var, , , ajax.php?