Reputation: 5
Currently trying to update a defined value with a form but it does not work for me. I did try several things even a function that updates the value with a +1 that works on another page so I am not sure what the problem with my form is.
<?php
if(isset($_POST['submitcounter'])){
function mail_counter(){
$val = $_POST['test']; //Increment the current count
update_option(CF7_COUNTER, $val); //Update the settings with the new count
}
}
/*
function update_counter(){
update_option(CF7_COUNTER, (int) $_POST['test']);
}
*/
?>
<h1>Settings Page</h1>
<form method="post" action="" >
<label for="Settings_text">Settings</label>
<input type="number" name="test" value="<?php echo get_option(CF7_COUNTER); ?>"/>
<input type="submit" name="submitcounter" value="update" class="button button-primary button-large">
</form>
The idea is for the function to replace the existing value ( whatever it may be 42 or 10209) with the input of the form.
Upvotes: 0
Views: 381
Reputation: 1148
<?php
if(isset($_POST['submitcounter']))
{
// Update the settings with the new count
update_option(CF7_COUNTER, $_POST['test']);
}
?>
<h1>Settings Page</h1>
<form method="post" action="" >
<label for="Settings_text">Settings</label>
<input type="number" name="test" value="<?=get_option(CF7_COUNTER);?>"/>
<input type="submit" name="submitcounter" value="update" class="button button-primary button-large">
</form>
Removed code not required and improved the readability of the code.
Upvotes: 0
Reputation: 23958
You need to call the function as code is written in function body and control is not going there:
if (isset($_POST['submitcounter'])) {
function mail_counter(){
$val = $_POST['test']; //Increment the current count
//Update the settings with the new count
update_option(CF7_COUNTER, $val);
}
mail_counter(); // This function is defined but not called.
}
Upvotes: 2