简体   繁体   中英

Redirect to the same page (without PHP)

I have a form that can be called from any page. It opens on top of the current page with z-index. I cannot use php in this case. The form is send to a cgi to process the values. It is necessary to put something in "redirect" if I leave it blank it don't works. In redirect is there a way to put the value to the current page whatever it is?

<Form id="formulari" method="POST" action="http://cgi.domain.com/FormMail.pl">
<p>
  <input type="hidden" name="recipient" value="info@domain">
  <input type="hidden" name="subject" value="IB4 correu">
  <input type="hidden" name="redirect" value="TheSamePageWeAre">  
</p>

<form>
<input type="text" name="name" value="name"/>
<input type="submit" value="Send"/>
</form>

Put this javascript at the end of the page.

<script type='text/javascript'>
  document.getElementsByName('redirect')[0].value = window.location.pathname;
</script>

Set an id on the hidden field, for example id="redirect" , and use this Javascript:

<script>
  window.onload = function (){
    document.getElementById('redirect').value = location
  }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM