如何将包含JS的PHP var放入表单值?

时间:2017-04-25 00:33:39

标签: javascript php forms

我有一个javascript来生成ETH地址和私钥。我想将私钥和地址的值输出到注册表单中的隐藏字段。

然而..

作为普通PHP,这会输出所需的结果:

$wallet_address = "<script type='text/javascript'>document.writeln(wallet.address);</script>";

echo $wallet_address;

但是,当我尝试将$wallet_address放入表单字段时:

<input type="hidden" name="user_wallet" id="user_wallet" class="input" value="<?php echo $wallet_address; ?>" />

我没有收到地址,我收到了javascript源代码行:<script type='text/javascript'>document.writeln(wallet.address);</script>

如何将$ wallet_address的值作为表单字段中的实际地址?

1 个答案:

答案 0 :(得分:0)

您回显脚本,而不是脚本的渲染;

做某事:

 $wallet_address = '<script type="text/javascript">function writeWallet(){ document.getElementById(user_wallet).value = "yourAdress";} window.onLoad(writeWallet);</script>';