ted_chou12 Posted December 18, 2006 Share Posted December 18, 2006 if I am not wrong, the confirm button should look like this:[code]<input type="submit" name="submit" value="Delete all Entries" onClick="if(checkDelete() == true) {return true;} else {return false;}">[/code]the javascript for it should look like this:[code]function checkDelete() {var value = confirm("Are you sure that you want to delete this entry and file?");if (value == true) {return true;} else {return false;}}[/code][code]if (checkDelete() == TRUE){$delete = unlink("$_SESSION[username]/posts.txt");if ($delete == true)echo "Entries succesfully cleared!<br>";elseecho "Error in clearing the entries!<br>";}[/code]and the php code should look like this:but i cant get it to work, the html and php code below the script dont show up, and the pop up doesn't work as well...can any suggest me what to change and in what order to put them together, such as which goes first what goes second.thanks so much.Ted. Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/ Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 The checkDate() Javascript function does not exists at all within php. Use...[code=php:0]if (isset($_POST['submit'])) { // do delete.}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/#findComment-143470 Share on other sites More sharing options...
JasonLewis Posted December 18, 2006 Share Posted December 18, 2006 he actually used checkDelete() not checkDate. but either way, this dosnt really have much to do with php. sept for the 2nd part.but just for some neatening and such. this:[code]<input type="submit" name="submit" value="Delete all Entries" onClick="if(checkDelete() == true) {return true;} else {return false;}">[/code]can be shortened to this:[code]<input type="submit" name="submit" value="Delete all Entries" onClick="javascript: return checkDelete()">[/code]because in the checkDelete() function you are returning it true or false anyway. then, for your PHP part do what thorpe suggested...instead of using checkDelete() == TRUE use:[code]if(isset($_POST['submit'])){//They pressed the submit button... process}else{//They are accessing the page without pressing the submit button... ERROR!}[code]That should all work... :) hopefully...[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/#findComment-143495 Share on other sites More sharing options...
ted_chou12 Posted December 18, 2006 Author Share Posted December 18, 2006 thanks, I will try it immediately. Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/#findComment-143497 Share on other sites More sharing options...
ted_chou12 Posted December 18, 2006 Author Share Posted December 18, 2006 sorry, ive got a question, where should I include the javascript part? does it have to be before all these or it doesnt matter? Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/#findComment-143500 Share on other sites More sharing options...
ted_chou12 Posted December 18, 2006 Author Share Posted December 18, 2006 okay, actually, ive got it working already, I placed it at the top in case any errors show up.so thanks. Quote Link to comment https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/#findComment-143505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.