I’m having some dificulties in understaning what’s going in your code. But I would suspect this problematic part is,
if(isset( $_POST['p_status_update'] ) ){
$renewal = $_POST['renewal'];
$frent = $_POST['future-rent'];
$available = $_POST['available'];
$deposit = $_POST['deposit'];
$lastShowing = $_POST['last-showing'];
$status = $_POST['status'];
$date = $_POST['date'];
$initials = $_POST['initials'];
$notes = $_POST['notes'];
update_option('renewal', $renewal);
update_option('future-rent', $frent);
update_option('available', $available);
update_option('deposit', $deposit);
update_option('last-showing', $lastShowing);
update_option('status', $status);
update_option('date', $date);
update_option('initials', $initials);
update_option('notes', $notes);
}
You’re just updating whatever there is on $_POST
to the different options. There should probably be some kind of conditionals to check that you’re getting the data you’re expecting and not overwriting anything that isn’t supposed to be overwritten.
To start debugging the code I would recommend you to add the following to the beginning of your page function.
function properties_status_page_handler(){
if ( isset($_POST['p_status_update']) ) {
// dump what is sent to the server
var_dump($_POST);
// log for later review
error_log(print_r($_POST, true));
// stop the code from executing, results in white screen with the $_POST dump showing
die;
}
// rest of the code
}
With this whenever you click your form’s submit button you get to see what actually gets sent to the server. So you would do,
- (Uncomment debugging if statement)
- Click submit to send the form
- Inspect the dumped form data
- Adjust your code
- Comment out the debugging if statement
- Refresh page and send the form again
- See what happened, rinse and repeat
As a side note, if the data you’re saving is related to single posts, you could consider using custom taxonomies (e.g. for status, renewal, app-pending..) for the data instead of saving it as options. Or if it is unique to posts, e.g. dates or deposit sum, then save the data as post meta. This way you’d save post related data in more “correct” place. This would make querying for different post easier as taxonomies and post meta are supported in WP_Query.
Also to make the rendering more clear, you could consider breaking the long function into smaller ones. For example, script in js file, styles in css file, posts query into a separate function (which returns posts), saving in one function, html structure in separate view file, etc.. And for the select options you can use selected()
.