Jump to content

[SOLVED] confirm submit with php


ted_chou12

Recommended Posts

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>";
else
echo "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.
Link to comment
https://forums.phpfreaks.com/topic/31076-solved-confirm-submit-with-php/
Share on other sites

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.