Is it possible in PHP to force the html in the page to scroll to a specific position? I may have shot myself in the foot, taking a long page that had a javascript form at the bottom, and turning it into a PHP file.But now when I do my page validation, any errors I report forces a page load, and the page does not get re-positioned by the browser as HTML pages do. This didn’t matter in a shorter form I did where the whole page was the form.
So if I place an html anchor tag down where the actual form starts, like <a name=”form”>, is there any way within my PHP code to make the browser jump to that position? I know I can jump to it by saying header( ‘Location:’ . “#form”);, but of course that totally reloads the page, clearing my variables.
... but of course that totally reloads the page, clearing my variables.
[/QUOTE]
<form
method="post"
action="<?= htmlspecialchars($_SERVER["PHP_SELF"]) ?>#check"
id="contactform"
<i>></i>
<div align="center" >
<a id="form"></a>
<div class = "strong">
</div>
<table bgcolor="#66ff66" border="1" width="90%" ><tr>
<td bgcolor="#66ff66" style ="text-align:right;" >
<p><span class="error">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* required fields.</span></p>
<form id="contactform" method="post" action="/guitarLessons.php#form">
Name: <span class="error">* Name is required</span>&nbsp;
<input type="text" name="name" value=""><br>
Email:&nbsp</span>&nbsp;
<input type="text" name="email" value=""><br>
Where are you:&nbsp; <input type="text" name="location" value=""><br>
Phone:&nbsp;<input type="text" name="phone" value=""><br><br>
<div align="center"> ---- <span class="error">*</span> Message ---- <span class="error">Please fill in the message field</span><br>
<textarea name="comments" wrap="physical" cols="65" rows="10" ></textarea>
<br><br>
<!-- forget this for now
File Attachment:&nbsp;<input type="file" name="file_attachment">
-->
</div>
<br> <input name="submit" type="submit" value="Submit">
</form>
</td</tr></table> <!-- mail form table -->
<form
id="contactForm"
method="post"
action="/guitarLessons.php#contactForm"
<i>></i>
<i> </i><div class="error">* required fields.</div>
<i> </i><fieldset>
<i> </i> <label for="contactName">Name: <b>*</b></label>
<i> </i> <input type="text" name="name" id="contactName" />
<i> </i> <br />
<i> </i> <label for="contactEmail">Email:</label>
<i> </i> <input type="text" name="email" id="contactEmail" />
<i> </i> <br />
<i> </i> <label for="contactLocation">Where are you:</label>
<i> </i> <input type="text" name="location" id="contactLocation" />
<i> </i> <br />
<i> </i> <label for="contactForm">Phone:</label>
<i> </i> <input type="text" name="phone" id="contactForm" />
<i> </i> <br />
<i> </i> <label for="contactMessage">Message: <b>*</b></label>
<i> </i> <textarea
<i> </i> name="comments"
<i> </i> id="contactMessage"
<i> </i> cols="65" rows="10"
<i> </i> ></textarea>
<i> </i> <br />
<i> </i></fieldset>
<i> </i><div id="submitsAndHiddens">
<i> </i> <input type="submit" class="submit" value="Submit">
<i> </i></div>
</form>
Well, it might help if you had built the form properly -- and weren't using tables for layout... or deprecated attributes like ALIGN on DIV... BGCOLOR on TABLE... anchor with name on it for nothing... non-breaking spaces for christmas knows what reason... Comment placements that could trip rendering bugs (yes, I said COMMENTS, yes... it sounds crazy, did I mention it's an IE thing?)
That whole page is a laundry list of outdated 1990's style markup. Pretty much EVERY table on that page belongs in the trash, some semantic markup wouldn't hurt.
<snip>
Silly question -- just how old is this site?[/QUOTE]
If I'm submitting to the same page I submitted the request from, I would simply leave the action empty. In this scenario the browser will submit to the current URL.
<form method="post" action="">
If I wanted to have it jump to a particular position on the page, I'd just add the # without and file.
<form method="post" action="#wheretogo">
So If I was submitting from "http://www.mysite.com/page.php ", the destination URLs respectively would be:
[URL]http://www.mysite.com/page.php[/URL]
[URL]http://www.mysite.com/page.php#wheretogo[/URL] [/QUOTE]
the reason i did this...
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . $formAnchorPos; ?>"
where "$formAnchorPos" might be "#wheretogo" or might be empty depending on the program activity, is because I'd read that there are security issues that were best dealt with referencing ($_SERVER["PHP_SELF"]), and then only after passing it through a function to remove the ind of suspicious characters that could be a hacker. I'm kind of new to PHP, so when I see warnings like that (and the example code works) I tend to go with it. So even if it works, are you saying its just as safe and effective to leave the action empty?[/QUOTE]
Not opposed to newer methods, just want to see better arguments for newer methods than to say my way is archaic.[/quote]
I starts to border on arrogance after a while.[/quote]
I've also been criticized for using GIFs instead of PNGs, despite the fact that PNG transparencies don't work on all browsers, and can't do simple animations.[/quote]
I've even been criticized for still using HTML symbols like @quot; instead of the UTF equivalents.[/quote]
So I continue to create pages that can be represented in 7-bit ASCII.[/quote]
And really... <br><br> means something is wrong? Everybody does that.[/quote]
They do because some browser will do the "right" thing and others won't, and its a simple way to ensure better layout in the majority of cases.[/quote]
but I don't buy the multiple arguments about changing things because the code style is dated.[/quote]
I wear many hats... electronic engineering, product design, software (started back with assembler on an ATARI!), musician, carpentry, modeling, costuming (hence the "hats" reference), and several other endeavors which all have something in common. That is, there is always a "newer" way of doing things. But newer is not always better[/quote]
I have no issue migrating more to divs with positioning controlled by CSS, but I do have a problem doing so just to avoid someone's teasing.[/quote]
judging by the many pages I've seen put out by modern CSS systems like Wordpress and Joomla that don't display right (even on some newer browsers), it tells me again that newer is not always better.[/quote]
But at least in the music world, what matters is what you play and the quality of your music and sound... not how old fashioned the electronics or style may be. See my point?[/QUOTE]
I'm going to answer this out-of-order, because some stuff at the top, middle and bottom can be answered all at once.
[/QUOTE]
0.1.9 — BETA 5.15