RE: [PHP] best method for relative linking in php
| From: | Brandon Orther | Date: | Sat, 22 Mar 2008 15:36:48 +0000 |
| Subject: | RE: [PHP] best method for relative linking in php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271975@lists.php.net to get a copy of this message | ||
Hello Sudhakar,
I have added #firstError to the end of my script url and then if I have an
error, I add that anchor to the first error on the page. This way I don't
have to use any javascript to leap the person forward to the first error.
I think this is what you are doing with your first method. That should be
Kind Regards,
Brandon Orther
-----Original Message-----
From: Sudhakar [mailto:sudhakararaog@gmail.com]
Sent: Saturday, March 22, 2008 4:26 AM
To: php-general@lists.php.net
Subject: [PHP] best method for relative linking in php
i have a registration page where a user fills a form and i display an error
message if a validation message needs to be displayed which i have written
in php. everything works fine. the way the form is made presently is there
is a huge amount of information relating to general information about the
form and its terms and conditions which is compulsory. so if i have to
display any validation message the user has to scroll the page from the top
again all the way till they see the validation message.
i have used relative linking as it is done in html, so that the user does
not have to scroll from the top of the page, rather the page stops where i
want it to so the user see the message and does not have to scroll the page.
following are the 2 methods i have used and both of them work fine. however
in method 2 as it is based on javascript and if
javascript is turned off the relative linking will not work and the user
will have to scroll from the top of the page again and i have tested this
myself.
method 1
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>#indrel"
method="POST"
id="test2" name="registrationform" >
<a name="indrel"></a>
if($error)
{
echo $error;
}
method 2
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>"
method="POST" id="test2"
name="registrationform" >
<a name="indrel"></a>
if($error)
{
echo ("
<script language='javascript' type='text/javascript'>
window.location.href='http://website.com/filename.php#indrel'
</script>
");
echo $error;
}
please comment if method 1 is correct in terms of the syntax of the form tag
if it is correct or not though i know this method is working the way i want
it to, i wanted to confirm before i implement it for my website.
please advice.
thanks.