Pick up Form URL

Asked

Viewed 112 times

-1

all right?

I have a form inside a certain folder, for example, domain.com/form/ but I will use this form inside another page, for example, domain.com/about where I would need when the user fills in this form to reach me the.com/about link he used to access the form and not where he is processed.

I tried to use: $page_reference = $_SERVER["HTTP_REFERER"]; but it always returns me where it is processed..

Is there any way?

Thank you.

  • What form are you using to put a form from one page to another? It would be good to insert this information into the body of the question.

1 answer

0

You can solve this by creating a field of type Hidden containing as value the address of the page, using the javascript window.Location this way:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script
    src="https://code.jquery.com/jquery-3.3.1.js"
    integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
    crossorigin="anonymous"></script>
</head>
<body>

<input type="hidden" name="endereco" id="endereco">
</body>
</html>
<script type="text/javascript">
    $("#endereco").val(window.location);
</script>

Note that if you specify the element you will see that in the field value will be the page link, and in your PHP code you will know where this form came from.

  • This way you’re also picking up only where the form is processed.. i am doing the following: I have the form hosted in dominioc.com.br/form - I put this form in lightbox on dominiob.com.br/about, I would need the address information to be: dominiob.com.br/about but he always returns me dominioc.com.br/form that is where the form is hosted

  • Impossible! o window.location() returns the current address of the page, that is, if the form is in domain.com returns domain.com, if you copy it and paste it into domain.com it returns a domain.com unless you are using a domain.com iframe I don’t know what the result would be.

  • I’m using an iframe..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.