CG_dude Posted February 12, 2009 Share Posted February 12, 2009 Hello everyone, thanks for taking time to read. I have a php script that enters or edits a text area. I am needing a password prompt to come up when the user clicks on submit. Previously I had written a javascript ( I don't care if it's not that secure), and it worked great except when the cancel button was clicked, it would still submit the new contents into the text area. Other than that, the script worked great, I've been to javascript forum and nobody seems to solve it either, so I thought I would possibly see if you guys can solve it either same cold or new, but I have tried onsubmit and onclcick. What might work is if the password promt would come up when the user clicks on the text area, but I'm not sure how to code that. Here is my code along with the java script that I am ok with removing. The issue may ly within the PHP script. <?php if(isset($_POST['submit'])) { //if submit was pressed $writefh = fopen($pafilename, "w+"); //File handle for $filename if(get_magic_quotes_gpc()){ $newcontents=stripslashes($_POST['editcontents']); } //strips unneeded backspaces by magicquotes else{ $newcontents = $_POST['editcontents']; } //NEXT 3 LINES ARE THE PROBLEM SPOT: fwrite($writefh, $newcontents, strlen($newcontents)); //Saves changes rewind($readfh); //resets cursor in file $contents = fread($readfh, filesize($pafilename)); //Updates $contents fclose($writefh); } ?> <form method="post" action="<? echo($PHP_SELF); ?>"> <textarea name="editcontents" style="width:200px; height:45px;"><? echo shell_exec('cat pa_box_settle_com.txt');?> </textarea> <br /> <P><input type="submit" name="submit" value="Comment"/> <script> function openSesame(me){ var password; var pass1="test"; var repeat=true; while(repeat){ var password = prompt("Please enter password",""); if(password!=null){ if(password == pass1){ me.type="submit"; alert('Password is correct! Click OK to proceed'); document.form[0].submit(); window.location.href="http://mysite/testprodcyc.php"; repeat=false; return false; }else{ alert('Password incorrect! Please re-enter password'); } }else{ me.type="button"; repeat = false; return false; } } } </script> <?php fclose($readfh); ?> </form> Thanks to anyone with an attempt Link to comment https://forums.phpfreaks.com/topic/144860-solved-problem-with-canceling-a-password-promt-on-submit/ Share on other sites More sharing options...
NightFalcon90909 Posted February 12, 2009 Share Posted February 12, 2009 I think you could do <textarea onfocus="openSesame();" name="editcontents" style="width:200px; height:45px;"><? echo shell_exec('cat pa_box_settle_com.txt');?> </textarea> That, or something close to that, would get the openSesame(); password prompt to come up as soon as they clicked into the textarea. But I'm horrifically inexperienced. =] Link to comment https://forums.phpfreaks.com/topic/144860-solved-problem-with-canceling-a-password-promt-on-submit/#findComment-760167 Share on other sites More sharing options...
CG_dude Posted February 12, 2009 Author Share Posted February 12, 2009 Hey Thanks NightFalcon, that worked with a few modifications, here is the script as it is now. <form method="post" action="<? echo($PHP_SELF); ?>"> <textarea onfocus="openSesame();" name="editcontents" style="width:200px; height:45px;"><? echo shell_exec('cat yourownteestfile.txt');?> </textarea> <br /> <P><input type="submit" name="submit" value="Comment"/> <script> function openSesame(){ var password; var pass1="test"; var repeat=true; do { password=prompt('Please enter password',''); if (password==pass1) { alert('Password is correct! Click OK to proceed'); document.form1.submit(); repeat=false; } else { alert('Password incorrect! Please re-enter password'); password = null; window.location.href="http://yourwebsite .php"; repeat=false; } } while (repeat); } </script> <?php fclose($readfh); ?> </form> Link to comment https://forums.phpfreaks.com/topic/144860-solved-problem-with-canceling-a-password-promt-on-submit/#findComment-760219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.