简体   繁体   中英

Auto-fill form on WordPress

I am using the Scripts n Styles plugin with this code to auto-fill a logged in user's email into form on WordPress:

<script type="text/javascript">
window.onload = function () {
document.getElementsByName("Element-Name")[0].value = "<?php $current_user->user_email ?>";
}
</script>

However, when I refresh the page I get the following text (the quoted value in the code above) instead of the actual value.

<?php $current_user->user_email ?>

Any idea what I am missing here? Is this an issue with the plugin?

The first thing I see is that you don't output anything. Try

<?php echo $current_user->user_email; ?>

But in your example it should have been just an empty value. There is something fishy with the PHP parser not detecting the PHP part.

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