form.submit and Netscape.

B

Bob Bedford

I've a code with redirect to a login page if nobody is registered. It works
fine on IE6, but I'm trying with NS, and it doesn't work.

Here is the code:

<form name="RedirectLogin" method="POST" action="login.php">
<input type="hidden" name="LogType" value="ManageProfile">
</form><script
language="javascript">document.forms["RedirectLogin"].submit();</script>

I've even tried with 'RedirectLogin', but it doesn't work either.

please help

Bob
 
M

Markus Fischer

Bob said:
I've a code with redirect to a login page if nobody is registered. It works
fine on IE6, but I'm trying with NS, and it doesn't work.

Here is the code:

<form name="RedirectLogin" method="POST" action="login.php">
<input type="hidden" name="LogType" value="ManageProfile">
</form><script
language="javascript">document.forms["RedirectLogin"].submit();</script>

I've even tried with 'RedirectLogin', but it doesn't work either.

Use the javascript-console to catch errors like this (Tools / Web Development / JavaScript Console).

You will get the message "Error: document.forms.RedirectLogin has no properties".

That's because you have you javascript-code inline to execute as soon as the browser has reached that point. But no one can guarantee you (and this is what you are seeing) that the part of the page you're refering to is already properly initialized in the browser internals.

Put your code in the onload-Handler, this ensures everything is loaded and that the form is accessible:

<script type="text/javascript">
window.onload = function() {
document.forms["RedirectLogin"].submit();
}
</script>

and remove the inline tag.

HTH
- Markus
 
V

VK

Netscape is traditionally slow in rendering forms (the payback for
multi-platform support). It could be that the form object is not initialized
by the moment of the function call, despite it comes after the form tag.

Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">
 
B

Bob Bedford

Hi both,

Thanks for your answers.
Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">

The code is generated by a PHP script that "redirect" only on some cases.
It's quite a long work to change things. It's there an other way ?

Bob
 
L

Lee

Bob Bedford said:
Hi both,

Thanks for your answers.
Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">

The code is generated by a PHP script that "redirect" only on some cases.
It's quite a long work to change things. It's there an other way ?

PHP can redirect to a new page without sending an intermediate
page to the client. Just send them the login page.
 
G

Grant Wagner

Bob said:
Hi both,

Thanks for your answers.
Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">

The code is generated by a PHP script that "redirect" only on some cases.
It's quite a long work to change things. It's there an other way ?

Bob

How is it "long work" to include the onload event dynamically?

<?php
if (whateverYourConditionIs) {
print "<body onload=\"document.forms['RedirectLogin'].submit();\">";
} else {
print "<body>";
}
?>

or

<?php
print "<body" .
(whateverYourConditionIs ? "
onload=\"document.forms['RedirectLogin'].submit();\"" : "") .
" style=\"margin:1em;\"" .
">";
?>

or

<body>
<!-- content -->
<?php
if (whateverYourConditionIs) {
print "<script type=\"text/javascript\">";
print "window.onload = function() {";
print "document.forms['RedirectLogin'].submit();";
print "}";
print "</script>";
}
?>
</body>

I probably missed several hundred other ways of accomplishing what you want
using PHP. This is what PHP (or any other server-side technology) is for, to
_dynamically_ create content based on certain logic, conditions or data. The
fact that the content PHP is generating is client-side JavaScript is
irrelevant to PHP.
 
B

Bob Bedford

Lee said:
Bob Bedford said:
Hi both,

Thanks for your answers.
Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">

The code is generated by a PHP script that "redirect" only on some cases.
It's quite a long work to change things. It's there an other way ?

PHP can redirect to a new page without sending an intermediate
page to the client. Just send them the login page.

The problem is that I send user's datas trough POST vars, instead of GET, so
the only way I've found to redirect to some pages with vars in POST, is to
create a FORM with the vars and then submit it. Maybe there is a better way
?

Bob
 
B

Bob Bedford

Grant Wagner said:
Bob said:
Hi both,

Thanks for your answers.
Use onLoad event instead.

<body onLoad='document.forms["RedirectLogin"].submit()';">

The code is generated by a PHP script that "redirect" only on some cases.
It's quite a long work to change things. It's there an other way ?

Bob

How is it "long work" to include the onload event dynamically?

<?php
if (whateverYourConditionIs) {
print "<body onload=\"document.forms['RedirectLogin'].submit();\">";
} else {
print "<body>";
}
?>

or

<?php
print "<body" .
(whateverYourConditionIs ? "
onload=\"document.forms['RedirectLogin'].submit();\"" : "") .
" style=\"margin:1em;\"" .
">";
?>

or

<body>
<!-- content -->
<?php
if (whateverYourConditionIs) {
print "<script type=\"text/javascript\">";
print "window.onload = function() {";
print "document.forms['RedirectLogin'].submit();";
print "}";
print "</script>";
}
?>
</body>

I probably missed several hundred other ways of accomplishing what you want
using PHP. This is what PHP (or any other server-side technology) is for, to
_dynamically_ create content based on certain logic, conditions or data. The
fact that the content PHP is generating is client-side JavaScript is
irrelevant to PHP.
Javascript can create dynamic <form> tag, as I send POST vars trough my
pages. I want to avoid to show various datas from my site, so for
redirecting, I've to create <form method="post"> and then submit it. If you
have a better way to redirect with post vars, please let me know.

Cheers.

Bob
 
M

Michael Winter

On Tue, 5 Oct 2004 16:46:55 +0200, Bob Bedford

[snip]
Javascript can create dynamic <form> tag, as I send POST vars trough my
pages. I want to avoid to show various datas from my site, so for
redirecting, I've to create <form method="post"> and then submit it. If
you have a better way to redirect with post vars, please let me know.

A PHP group would be a better place to ask:

comp.lang.php
alt.comp.lang.php

Mike
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top