Situation: A user is viewing a web-page using the contact option provided. Upon clicking 'Contact', I'd like to pass the URL of the currently viewed page as text into a field of that contact form.
The starting point is any HTML page (page-xy.html). The existing contact-form is written in PHP, HTML and CSS (contact.php) and does function fine. I assume a Javascript may help to accomplish this procedure.
Upon clicking the 'Contact' button, this Javascript command reads the current URL:
var strReferrer=window.location.href;
The question is how to pass this variable 'strReferrer' on to 'contact.php' that is being opened?
In the following开发者_C百科 the variable should be inserted into the message text field for example. I'd rather not use a cookie for this.Hope someone has suggestions leading to the solution, thanks.
My goal is just about the reverse of the problem described in this thread
Just use a hidden input field.
<form ...>
<!-- Your contact form goes here -->
<input type="hidden" id="strReferrer" name="strReferrer" value="whatever" />
</form>
You can have javascript set the value if you want.
Here is the solution that I have implemented.
In any HTML page with a contact option, call a simple script as stated below. In case JS is not available the contact form opens via 'href' and of course without the originating URL.
<a href="/contact/contact-form.php" title="send an eMail" onclick="return(contact())">Contact the author</a>
... that puts the string of the current URL into 'strReferrer' and opens a new window with your contact-form.php
<script>
var strReferrer = location.href;
function contact() {
window.open("/contact/contact-form.php?sourceURL="+strReferrer);
return false;}
</script>
PHP queries the string with 'strReferrer' and keeps it in '$params'. in contact-form.php:
//get the URL from the originating page (where this form has been called from)
$params = $_SERVER['QUERY_STRING'];
...
...
// Insert '$params' into the text as part of the text to be eMailed.
// the eMail Content Header for the recipient
$_POST["text"] = $_POST["send"]["author"]." with e-mail address: ".$_POST["send"]["mail"]." sent the msg below: \n <$params> \n \n $texto";
Now you know the page-url your visitors have decided to contact you.
Insert this line in form and you give referer at form data prelucration.
<input type="hidden" id="referer" name="referer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
I'm solving a similar problem here
I'm using this code to capture the page url
<script type="text/javascript">
var segments = window.location.pathname.split('/');
var toDelete = [];
for (var i = 0; i < segments.length; i++) {
if (segments[i].length < 1) {
toDelete.push(i);
}
}
for (var i = 0; i < toDelete.length; i++) {
segments.splice(i, 1);
}
var filename = segments[segments.length - 1];
console.log(filename);
document.write(filename);
</script>
but how to i put it inside a contact form textbox? (I'm using a wordpress contact form plugin)
see here: https://nationalland.co.uk/tw31sp
精彩评论