shmideo Posted July 29, 2016 Share Posted July 29, 2016 Hi Been struggling to find a way to automatically go to the top of the page after the php contact form is executed, when the success message is displayed. Probhlem I have is that the form is quite long and when it is filled in the success or failure message is not fully seen as it displays at the top. Thanks Code below: <div class="row"> <div class="col-md-6"> <div class="offset-anchor" id="contact-sent"></div> <?php if (isset($arrResult)) { if($arrResult['response'] == 'success') { ?> <div class="alert alert-success" id="contactSuccess"> <strong>Success!</strong> Your message has been sent to us. </div> <?php } else if($arrResult['response'] == 'error') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> There was an error sending your message. (<?php echo $arrResult['error'];?>) </div> <?php } else if($arrResult['response'] == 'captchaError') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> Verificantion failed. </div> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/301689-move-to-top-of-page-after-execution/ Share on other sites More sharing options...
kicken Posted July 29, 2016 Share Posted July 29, 2016 If you're doing a normal submit then the page would be reloaded and start at the top automatically. Are you using Ajax or something to submit the form or some other method that prevents a page reload? Quote Link to comment https://forums.phpfreaks.com/topic/301689-move-to-top-of-page-after-execution/#findComment-1535304 Share on other sites More sharing options...
shmideo Posted July 29, 2016 Author Share Posted July 29, 2016 Thanks for your reply. Well the submit part is done in a standard html way, the validation is done in php which is part of the same file. It doesn't reload the page after submit, hence you have to scroll up. to see the message. Quote Link to comment https://forums.phpfreaks.com/topic/301689-move-to-top-of-page-after-execution/#findComment-1535309 Share on other sites More sharing options...
maxxd Posted July 29, 2016 Share Posted July 29, 2016 Unless you're using AJAX, the page has to be submitted before PHP can get the variables to validate. So the page should refresh and automatically be at the top... Perhaps post the form and validation code? Quote Link to comment https://forums.phpfreaks.com/topic/301689-move-to-top-of-page-after-execution/#findComment-1535311 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.