View Full Version : passing form variables

09-25-2003, 08:18 AM
I have a form, in there have a save and delete button, when click delete button, then there will hv a pop up window to ask is really to delete the record or not. and then will return to the form in the main window to do the delete process. I am now stuck in the point that how I can pass the form variable to the pop up wiondow and then back to the form? since i use java script to open the pop up window, the session variable cannot work for it... so any other method?

my code is like this:

<script type="text/javascript">
function CheckDelete() {
var answer = confirm ("Are you sure you want to delete this record?")
if (answer) { window.location="delete.php"; } }
<input type="button" name="Submit2" value="Del" onclick="javascript:CheckDelete()">

09-25-2003, 10:54 AM
Welcome here.

Since you want to do it with clientsided javascript, you'd beeter have posted it in the javascript forum.

But ... not all users have javascript enabled (about 11% i've read somewhere) so tey would miss the dialog. It's better to take care of this serversided, with PHP. You can respond with a page where you center a <div> with a form in it. Then you can store all formvalues in there as hidden formfields with the same names as in the initial form, and display the buttons you need (all as submitbuttons with the same name ("action" or so), but with a different value). In the page, you post this 'dialog' to, you then run some code, depending on the value of $_POST['action']. (All formfields are accesable just as if the initial form was posted straigth to this page).

(Even better but a bit more complex, is posting the form to itself (both the initial form as the dialog form have the pages name in the action-attribute) and then use a hidden formfield to determine the state of the form. Just post back if you would like to try it with such a multi-pupose page.)