Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.