Jump to content

Recommended Posts

Hi, I am using this bit of code

 

<script type="text/javascript">
$(document).ready(function() {
  $('#countdown').countdown({seconds: 10})
  setTimeout(function() {
  window.location.href = "index.php";
}, 10000);
});
</script>

 

to reload the page after contact us form is submitted, here it will reload index.php, however I am running this script on more than one page how can I make it reload from current url?

Also I would I include

javascript: return null;

to stop the page jumping to top once form is submitted...Many Thanks for you help

Link to comment
https://forums.phpfreaks.com/topic/256039-help-with-windowlocationhref-pls/
Share on other sites

<script type="text/javascript">

$(document).ready(function() {

  $('#countdown').countdown({seconds: 10})
  setTimeout(function() {
  window.location.reload()
}, 10000);


});

Like this? when I do this the form keeps submitting / resending


</script>

I would advise against what you're trying to do. After the form has been submitted and the page has finished loading, I don't see any benefit in refreshing the page? Keep requests to a minimum. The way I would do it would be to just display a little confirmation message above the form, notifying the user their message was sent successfully. That's it.

 

Having said that, if you really want to do it, I would add a callback event to the countdown. Looks like you can use "onExpiry", assuming I'm looking at the right countdown plug-in:

 

$(document).ready(function() {
    $('#countdown').countdown({
        seconds: 10,
        onExpiry: function() {
            window.location.reload();
        }
    })
});

 

I copy and paste your code, but the form didn't load after submitting...

Keep requests to a minimum. The way I would do it would be to just display a little confirmation message above the form, notifying the user their message was sent successfully. That's it

 

Can you show me how you would do it...sorry but I'm rubbish with JavaScript.

On successfully sending the message, I would redirect back to the same page with a simple flag in the URL:

 

if ($message_sent) {
    header('Location: index.php?sent');
    exit;
}

 

Then when displaying the contact form:

 

<?php if (isset($_GET['sent'])): ?>
    <p class="success">Thank you, your message has been sent.</p>
<?php endif; ?>

<!-- Contact form here.. -->

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.