terungwa Posted April 22, 2014 Share Posted April 22, 2014 On my current blog development project,when the user clicks post reply, is there a way I can have the page retain it's location or to auto scroll the user back down to where they clicked post reply at the buttom of the page? This is most useful when the reply or comment thread is long. Also when their is an error when a user posts a reply, he also needs to be auto scrolled down to the reply/comment form and not the top of the page. Kindly advice steps i may take to address this. Point to note: The reply form posts to itselt, that is the action attribute is blank.Find below an excerpt of my reply.php script. if (isset($_POST['post_reply'])) { $missing = array();//Declare An Array to store any error message if (empty($reply)) { $missing[] = 'Please Enter a reply.'; } if (empty($missing)) { // initialize flag $OK = false; // initialize prepared statement $stmt = $mysqli->stmt_init(); // create SQL $sql = 'INSERT INTO comments (post_content, post_date, post_topic, post_by) VALUES(?, NOW(), ?, ?)'; if ($stmt->prepare($sql)) { // bind parameters and execute statement $stmt->bind_param('sis', $reply, $id, $Memberid); // execute and get number of affected rows $stmt->execute(); if ($stmt->affected_rows > 0) { $OK = true;} } } } if(isset($missing)) { echo '<div class="panel callout error"> <ul>'; foreach ($missing as $key => $values) { echo '<li>'.$values.'</li>'; } echo '</ul></div>'; } //show reply box echo '<form method="post" action=""> <textarea name="reply-content" rows="9"></textarea><br /><br /> <input type="submit" value="Submit reply" name="post_reply" /> </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/287953-returning-to-the-same-point-in-a-page-after-form-submission/ Share on other sites More sharing options...
Solution davidannis Posted April 22, 2014 Solution Share Posted April 22, 2014 I've never tried it but seems to me you can add an anchor to the blank post. echo '<form method="post" action="#myanchorname"> then you need to have <a name="myanchorname"></a> on the page where you want to come back to Quote Link to comment https://forums.phpfreaks.com/topic/287953-returning-to-the-same-point-in-a-page-after-form-submission/#findComment-1477018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.