I am working on a form submission page (POST) that displays all current users (as checkbox objects at the beginning of the form), using file_get_contents() of an htpasswd file, and allows the user to update these users with the exec() function. This all works correctly, except for the fact that the user list displayed on the page is not updated after the user submits their changes via the form submit button. I know that the reason this happens is because the code to update the results occurs after the echo of the results.
So my question is: Is there any way to modify/update the output (with PHP) that would occur before the actual functions are executed? I have included my basic code structure to help visualize my situation:
form.php:
<form method="post">
<?php
//Code to read htpasswd file, then output results as form input checkboxes
?>
<select name="action">
<option value=""></option>
<option value="delete"></option>
<option value="change"></option>
<option value="create"></option>
</select>
<input type="submit">
<?php
if($_POST['action'] !== '')
{
switch($_POST['action'])
{
case delete:
//run exec() command to delete each user
case change:
//run exec() command to change pw for each user
case create:
//run exec() command to create a user
}
}
?>
If this is not possible with PHP, will Javascript do the job?