Location.href is not redirected to https: // urls

We used the following on the "Thank you" form page to redirect back to the form in 5 seconds and carefully pre-populate the name fields with the values:

<script> setTimeout(function() {location.href = '<?php echo $var3['returnurl'] ?>?fullName[first]=<?php echo $var1['first'] ?>&fullName[last]=<?php echo $var2['last'] ?>'}, 5000); </script> 

Works fine until the returnurl field is https: // url. He then stays on the thankyou page in a loop, trying to do a redirect. There are no iframes involved .... tried top.location.href ... not good ... even tried location.replace

Can anyone see any restrictions with code that could affect the redirect to https: // url.

Code in php file ...

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no"> <meta name="HandheldFriendly" content="True"> <meta name="MobileOptimized" content="width"> <title>Thankyou</title> <style type="text/css"> body { margin: 0px; padding: 0px; background: #fff; font-family: Arial; } #message { position: absolute; left: 50%; width: 320px; margin-left: -160px; } </style> <?php $answers = $_POST; $var1 = array("first" => $answers[fullname][0]); $var2 = array("last" => $answers[fullname][1]); $var3 = array("returnurl" => $answers[returnurl]); ?> </head> <body> <script> setTimeout(function() {location.href = '<?php echo $var3['returnurl'] ?>?fullName[first]=<?php echo $var1['first'] ?>&fullName[last]=<?php echo $var2['last'] ?>'}, 5000); // this duration is in millisecs </script> <div id="message"> <p>&nbsp;</p> <div style="text-align: center;"><h1>Thank You!</h1></div> <div style="text-align: center;">Your submission has been received.</div> <div style="text-align: center;">We're most grateful</div> <div style="text-align: center;">&nbsp;</div> <div style="text-align: center;"><img src="http://www.mazeguy.net/bigsmilies/thumbsup.gif"></img></div> <div style="text-align: center;">&nbsp;</div> <div style="text-align: center;">You will return in 5 seconds</div><br /> </body> </html> 

Here is the result of the submission ... the source of the "Thank you" page shows ... yes, the secure URL of the page does not pass ...

 <script> setTimeout(function() {location.href = '?fullName[first]=&fullName[last]='}, 5000); // this duration is in millisecs </script> 
+4
source share
1 answer

Have you considered submitting a form via Ajax? The user never leaves the form submission page. You can simply display a modal confirmation message. This seems easier than redirecting the user. It can be nicer for users.

Suppose your form has a submit button with the class 'submit'. In jQuery you could do something like this:

 $(function() { $('body').on('click', '.submit', function(event) { event.preventDefault(); var target = event.currenTarget; var form = $(target).closest('form'); var action = $(form).attr('action'); $.post(action, form.serialize()) .done(function() { alert('Thanks for your submission!'); }) .fail(function() { alert('Oops! Something went wrong... PLease try again.'); }); }); }); 

Check out Bootstrap JS. They have great models that you can use.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1494838/


All Articles