Reputation: 291
I have a html code and php code that will execute a program when the I hit the submit button. I'm trying execute my code while the Submit button is disabled. The button disabled but it did not execute my php code. Is there a condition for if(isset) when the button is disabled? Can you give me tips on this?
Here's my html code:
<form method ="POST">
<input type="submit" name="submit" value="GENERATE report" onclick="this.disabled=true;"> <br />
Here's my php code
<?php
if (isset($_POST['submit'])) {
echo '<script language="javascript">';
echo 'alert("disabled")';
echo '</script>';
}
?>
Upvotes: 0
Views: 2504
Reputation: 401
I'd advice you to go through the link https://www.w3schools.com/jsref/prop_submit_disabled.asp
the submit button is valid only if its not disabled.
The onclick function you specified disables your submit button and since it only submits after executing the onclick, after the onclick the button is no longer valid and hence the form will not be submitted.
due to this the request will not be sent to the server and the PHP code you wrote will not be executed at all.
whatever your intention might be, I suggest you call a function on onclick and in that function, disable the submit button and then alert that the button is disabled. your current method will not work.
Upvotes: 1
Reputation: 1811
You need to disable the button after submitting the form.
or use condition to disable the button.
<input type="submit" name="submit" value="GENERATE report" <?php if(isset($_POST['submit'])) echo 'disabled="disabled"'; ?> > <br />
Upvotes: 1