Reload page when HTML in <iframe src> changes

P

P E Schoen

I have a list of emails (in an HTML file) that are displayed on a page in an
iframe. I also have text inputs for name, email, and a password, so that
authorized users can add their emails. The emails are kept in an SQLite
database and are accessed by a PHP script which checks authorization,
disallows duplicates, and then echoes success or failure. If it succeeds, it
updates the HTML email list in alphabetical order in the HTML file. When the
user navigates back to the original form, I want the page to be refreshed so
it shows the newly inserted email.

There were several methods discussed on some websites I found, but most of
them seemed rather complex. They often used a meta refresh, or something
like this:

window.location.reload();
location.reload(true);
location.href = location.href;
history.go(0);

http://irt.org/script/redirect.htm
http://api.jquery.com/load/
http://www.w3.org/QA/Tips/reback

Here is what I did:

<script type="text/javascript">
function CheckModified() {
if (Form1.Modified.value != "NO") {
document.location.reload(true); // true = reload from server
}
}

function SubmitEmail() {
Form1.Modified.value = "YES";
document.forms["Form1"].submit();
}
</script>

<body onLoad = "CheckModified();">
<form id="Form1" action="../cgi-bin/BGFemail2.php" method="POST">
<input type="hidden" name = "Modified" value="NO">

There is only one problem with this, as far as I can see. If the script
fails, the reload is not needed, and in fact it clears the text input fields
so they must be retyped if you want to try again.

Is there a "better" way?

This can be seen at:
http://www.pauleschoen.com/bgf/BGFemail2.htm

It will eventually be used on this website:
www.baltimoregreenforum.org

Thanks,

Paul
 
A

Adrienne Boswell

Gazing into my crystal ball I observed "P E Schoen"
I have a list of emails (in an HTML file) that are displayed on a page
in an iframe. I also have text inputs for name, email, and a password,
so that authorized users can add their emails. The emails are kept in
an SQLite database and are accessed by a PHP script which checks
authorization, disallows duplicates, and then echoes success or
failure. If it succeeds, it updates the HTML email list in
alphabetical order in the HTML file. When the user navigates back to
the original form, I want the page to be refreshed so it shows the
newly inserted email.

I would do something like:

<?php
'form processing stuff

?>

<div id="emailist">
<ul>
<?php
$sql = "SELECT email FROM table ORDER BY email";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_NUM)){
echo "<li>".trim($row[0])."</li>";

}
mysql_free_result($rs);
?>
</ul>
</div>
<div id="inputform">
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<!-- rest of form -->
</form>
</div>

I would set the emaillist div to float left, with a certain width, and
overflow to scroll. If the form posts to itself, there is no need to use
an iframe or client side script.

Just a thought.
 
P

P E Schoen

"Adrienne Boswell" wrote in message
I would do something like:
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
I would set the emaillist div to float left, with a certain width,
and overflow to scroll. If the form posts to itself, there is no
need to use an iframe or client side script.

That might be a good idea, and it's certainly simpler. But I tried it and
each time the form method is called, it advances the browser history, so the
back button must be clicked for each email added, to return to the original
page that invoked this email list. It's not a huge problem, but I think I'll
stay with essentially what I have now, unless that can be fixed. Maybe use
history(0)?

Thanks,

Paul
 
A

Adrienne Boswell

Gazing into my crystal ball I observed "P E Schoen"
"Adrienne Boswell" wrote in message
I would do something like:
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">

I would set the emaillist div to float left, with a certain width,
and overflow to scroll. If the form posts to itself, there is no
need to use an iframe or client side script.

That might be a good idea, and it's certainly simpler. But I tried it
and each time the form method is called, it advances the browser
history, so the back button must be clicked for each email added, to
return to the original page that invoked this email list. It's not a
huge problem, but I think I'll stay with essentially what I have now,
unless that can be fixed. Maybe use history(0)?

Thanks,

Paul

Do you want the user to be able to add more emails? If so, this should
not be a problem. If you don't want them to be able to add more emails,
just hide the div with the form, eg:

<?php if(!$isposted){ ?>
<div id="inputform">
<!-- blah -->
</div>
<?php }?>
<p><a href="otherpage.php">Go to other page</a></p>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top