Reputation: 825
I have the following code:
<?php
$post_test = filter_input(INPUT_POST, 'test');
if (isset($post_test)) {
echo 'has data';
// ********************
// it is not going here
// ********************
}
<form role="form" action="" method="post">
// some form fields here
<button type="submit" name="test" class="form-button" onclick="this.form.submit(); this.disabled=true; ">Send</button>
</form>
I want to disable the button when i submit. But it is not going inside the php code I highlighted above and there's no data. So I resorted to this just to fake the disabling:
<form role="form" action="" method="post">
<button type="submit" name="test" class="form-button" onclick="this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Please advise.
Updated
<?php
$post_test = filter_input(INPUT_POST, 'test');
if (isset($post_test)) {
echo 'has data';
// ********************
// it is not going here
// ********************
}
?>
<form role="form" action="" method="post">
// some form fields here
<button type="submit" name="test" value="1" class="form-button" onclick="this.form.submit(); this.disabled=true; this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Upvotes: 0
Views: 53
Reputation: 2545
Instead of performing the check on the name
of the submit button, create an hidden element with name test and value 1.
<form role="form" action="" method="post">
<input type="hidden" name="test" value="1" />
<button type="submit" class="form-button" onmouseup="this.form.submit(); this.disabled=true; this.className='button-disabled'; this.innerHTML='Sending...'; ">Send</button>
</form>
Upvotes: 1