0

How can I disable submit button on this php script How can I prevent multiple clicks for Add Career button and Remove Career Button

Here is the script

If it's possible, the buttons should be disabled 1 hour for each user.

<?php 
// gets current value 
if(isset($_POST['output'])){ 
    $value = $_POST['output']; 
} else { 
    $value = 0; 
} 
if($_POST['Add']){ 
    // opens the file for reading 
    $read = fopen("file.txt", 'r'); 
    // stores the file as variable cNumAdd 
    $cNumAdd = fread($read, 512); 
    // closes file 
    fclose($read); 
     
    // opens file again 
    $write = fopen("file.txt", "w+"); 
    // adds 1 to the data on the file 
    $cNumAdd = $cNumAdd + 1; 
    // writes the data into the file 
    fwrite($write, $cNumAdd); 
    // closes file 
    fclose($write); 
} 
// comments are the same as above except for subtracting 1 from file 
if($_POST['Remove']){ 
    $read = fopen("file.txt", 'r'); 
    $cNumRemove = fread($read, 512); 
    fclose($read); 
     
    $write = fopen("file.txt", "w+"); 
    $cNumRemove = $cNumRemove - 1; 
    fwrite($write, $cNumRemove); 
    fclose($write); 
} 
?> 


<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">  
<input type="submit" name="Add" value="Add Career">  
<input type="submit" name="Remove" value="Remove Career">  
<input type="text" name="output" value="<?php include("file.txt"); ?> "> 
</form>
K3v
  • 71
  • 7
  • 2
    create session to store current time as soon as a button is hit and add disabled attrib in the button and expire the session after one hour and remove the disabled attrib. That's all. – Mawia HL Apr 01 '16 at 19:36
  • 2
    +1 for the first comment. Second to that, you can use JavaScript / jQuery to handle the disabling part and you will need codes to handle the 1 hour time tracking portion; That you will wrap the JavaScript/ jQuery in. – yardie Apr 01 '16 at 19:36
  • Sorry but I'm new to jquery and javascript can you send me a code how can I do that? – K3v Apr 01 '16 at 20:16
  • 1
    Stack Overflow is not a *give me the code* kind of girl ;) – Jay Blanchard Apr 01 '16 at 21:10
  • This might also be of some use http://stackoverflow.com/questions/34376536/stop-multiple-submits-for-a-html-from/34377412#34377412 also this one http://stackoverflow.com/questions/36095841/php-replace-a-button-with-text-when-clicked/36096288#36096288 for some other Javascript bits doing something similar - removing the button altogether once clicked.. – Steve Apr 01 '16 at 22:09
  • Sorry @JayBlanchard I didn't knew that – K3v Apr 02 '16 at 06:26

0 Answers0