Jump to content

getting user confirmation


harvey

Recommended Posts

You could use a form:

//modification of mgallforever's code
<?php
echo "<form method=POST action=\"writetofile.php\">";
if(file_exists("/path/to/the/file.txt")){
echo "The file exists, would you like to overwrite it?<br>
<input type=submit name=\"overwrite\" value=\"yes\">
<input type=submit name=\"overwrite\" value=\"no\">\n";
}else {
echo "File doesn't exist, would you like to create it?<bR>
<input type=submit name=\"create\" value=\"yes\">
<input type=submit name=\"create\" value=\"no\">\n";
}
echo "</form>";
?>

Link to comment
Share on other sites

You can do everything in one file. Just use

if (isset($_POST['overwrite']))

 

To see if it is currently getting the overwrite answer. If it isn't it should be checking if the file exists. I have written a number of applications in a single php file.

 

There is no way to get a user event in the middle of a php script running so there is no other way than to pass it to the file one more time.

Link to comment
Share on other sites

Hmm. I'm still not quite getting it (but appreciate your help). If I understand, your suggestion is something like:

  step 1.  originalform.php --> (post filename, contents) --> process.php

  step 2. process.php --> (post answer to yes/no confirmation) --> process.php

 

Now process.php can test for isset($_POST['overwrite']). Let's say the value is 'yes'.

However, on the second call (to itself) it has lost the values to, $_POST['filename'] and $_POST['contents'].

 

Or is your suggestion that originalform.php is the only file I need?? (Sorry to be so dense.)

Perhaps if you have a small (but complete) toy example?

 

Harvey

   

Link to comment
Share on other sites

In the <form> that has the overwrite button, include a hidden field with the other values:

//modification of mgallforever's code
<?php
echo "<form method=POST action=\"writetofile.php\">";
if(file_exists("/path/to/the/file.txt")){
echo "The file exists, would you like to overwrite it?<br>
<input type=submit name=\"overwrite\" value=\"yes\">
<input type=submit name=\"overwrite\" value=\"no\">\n";
}else {
echo "File doesn't exist, would you like to create it?<bR>
<input type=submit name=\"create\" value=\"yes\">
<input type=submit name=\"create\" value=\"no\">\n";
}
echo <input type=HIDDEN name=\"filename\" value=\"" . $_POST['filename'] . "\">
       <input type=HIDDEN name=\"contents\" value=\"" . $_POST['contents'] . "\">";
echo "</form>";
?>

 

Then those two values won't be lost.

Link to comment
Share on other sites

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.