PHP POST method using javascript
Posted: Tue Sep 22, 2009 1:34 pm
This is my situation:
I have a directory listing script that lists through directories with backups. Each file (backup) has link labeled "restore" which trigger a javascript function submitPostLink() and that function trigger another script which restore selected backup.
The important part of a code is:
$file[$i] is a variable with a current name of a file. I need that to POST it not to GET it and it has to be a hyperlink not a button or something like that. That's why I'm using a javascript, to submit that form.
When I'm listing a directory with only one backup and I click on restore hyperlink, it works well, but when there are more than one backup, the javascript function is called with a right variable (I know that because 'confirm("Do you really want to restore backup "+ file +"?"))' has a right variable file) but will not submit that form.
Could you help me sort it out, please?
I have a directory listing script that lists through directories with backups. Each file (backup) has link labeled "restore" which trigger a javascript function submitPostLink() and that function trigger another script which restore selected backup.
The important part of a code is:
Code: Select all
<script language=javascript type=text/javascript>
function submitPostLink(file) {
if(confirm("Do you really want to restore backup "+ file +"?")) {
document.postlink['backup'].value = file;
document.postlink.submit();
}
}
</script>
<form action="index.php" name=postlink method="post">
<input type="hidden" name="backup" value="">
<a href=# onclick="submitPostLink('<?php echo $files[$i] ?>');">restore</a>
When I'm listing a directory with only one backup and I click on restore hyperlink, it works well, but when there are more than one backup, the javascript function is called with a right variable (I know that because 'confirm("Do you really want to restore backup "+ file +"?"))' has a right variable file) but will not submit that form.
Could you help me sort it out, please?