Html 创建一个自动填充目标页面上的字段的链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8252222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:38:50  来源:igfitidea点击:

Create a link that automatically fills a field on the target page

htmlhyperlinknewsletter

提问by manujj88

I'm coding a newsletter and the guy that asked me to do it wants a link in it...all perfect no problems...

我正在编写时事通讯,而要求我这样做的人想要其中的链接......一切完美没问题......

Now the problem is that when you click on this link it goes on a page with fields and the guy asked me if it's possible to automatically fill up one of the fields.

现在的问题是,当你点击这个链接时,它会进入一个带有字段的页面,那个人问我是否可以自动填写其中一个字段。

The page is a subscription page for some services and this guy wants me to fill up the referral field automatically when you land on the page with his email. Is it possible?

该页面是某些服务的订阅页面,当您使用他的电子邮件登陆该页面时,这个人希望我自动填写推荐字段。是否可以?

Thanks heaps

谢谢堆

回答by T.Rob

One way to do this is to place the field name and value in the query string. The "query string" is the part of a URL which contains field/value pairs. It is separated from the page address by a ?followed by field=value pairs separated by &characters. For example,

一种方法是将字段名称和值放在查询字符串中。“查询字符串”是包含字段/值对的 URL 的一部分。它通过?后跟字段=值对与页面地址分开,由&字符分隔。例如,

http://www.example.com

...would become...

...会成为...

http://www.example.com?fieldName=fieldValue

In order for this to work, the page must parse the field as part of the HTTP GETrequest and then return the value as a pre-filled field. If the form is properly validated at the server side then it usually already has this capability of parsing fields and retaining their values across multiple submissions of the same form. This is because doing so allows the page to be redrawn with an error message if some fields are blank or have invalid values.

为了使其工作,页面必须将该字段解析为 HTTPGET请求的一部分,然后将该值作为预填充字段返回。如果表单在服务器端正确验证,那么它通常已经具有解析字段并在同一表单的多次提交中保留它们的值的能力。这是因为如果某些字段为空或具有无效值,则这样做允许使用错误消息重新绘制页面。

This is very easy to test - just find the field name in the page source and extend the URL you are currently using as shown above. If it works you are done. If not, you may need to get the code on the server side updated to accept the field as part of the query string.

这很容易测试 - 只需在页面源中找到字段名称并扩展您当前使用的 URL,如上所示。如果它有效,你就完成了。如果没有,您可能需要更新服务器端的代码以接受该字段作为查询字符串的一部分。

Other ways to accomplish the same thing are more dependent on the server-side code. For example, many sites embed the associate referral ID in the URL such as:

完成相同事情的其他方法更多地依赖于服务器端代码。例如,许多站点在 URL 中嵌入了关联推荐 ID,例如:

http://www.example.com/123456/

In this case, server-side code interprets the directory path as a field and parses it accordingly. Because this requires very specific server-side code to support it, the first option is probably your best bet.

在这种情况下,服务器端代码将目录路径解释为一个字段并相应地对其进行解析。因为这需要非常具体的服务器端代码来支持它,所以第一个选项可能是您最好的选择。

回答by Julius

Encountered this issue, and the following Javascript code did the trick.

遇到了这个问题,下面的 Javascript 代码解决了这个问题。

Using @T.Robquery string parameters.

使用@T.Rob查询字符串参数。

HTML CODE:

HTML代码:

<input type="text" name="fillfield" id="fillfield" style="width: 350px;" class="input" value=""/>

JAVASCRIPT CODE:

爪哇代码:

window.onload=function(){ 

 function querySt(ji) {

 hu = window.location.search.substring(1); 
 gy = hu.split("&");

for (i=0;i<gy.length;i++) { 
ft = gy[i].split("="); 
if (ft[0] == ji) { 
 return ft[1]; 
 } 
 } 
 } 
 var fieldName = querySt("fieldName");


 if( fieldName==null){ 
 }else{ 
 document.getElementById('fillfield').value = fieldName; 
 } 
 } 

When you visit http://www.example.com?fieldName=fieldValueit would automatically fill in fieldValueto the fillfieldinput.

当您访问时,http://www.example.com?fieldName=fieldValue它会自动填写fieldValuefillfield输入中。

回答by user3555228

Using php

使用 php

<?

$passthis = "See you on the other side";

echo '<form action="whereyouwantittogo.php" target="_blank" method="post">'.
'<input type="text" name="passthis1" value="'.
$passthis .' " /> '.
'<button type="Submit" value="Submit" >Submit</button>'.
'</form>';

?>

The script for the page you would like to pass the info to:

您要将信息传递到的页面的脚本:

<?

$thispassed = $_POST['passthis1'];

echo '<textarea>'. $thispassed .'</textarea>';
echo $thispassed;

?>

Use this two codes on seperate pages with the latter at whereyouwantittogo.php and you should be in business.

在单独的页面上使用这两个代码,后者在 whereyouwantittogo.php 上,您应该可以开展业务。