有没有一种方法可以让profile.getEmail()返回值来填充html表单中的输入字段



所以基本上我想将profile.getEmail((获取到电子邮件表单输入或em中。如果这个问题很愚蠢,我很抱歉,但我已经在这件事上浪费了好几天时间。使用表单输入字段中的数据,我将在golang服务器上进行插入查询。因此,实际上我需要来自谷歌账户的数据来注册和/或登录服务器。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Index</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="MYCLIENTID">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />

</head>
<body>
<h1>Login</h1> 
<form action ="/login_process" method="POST">
<label for="email">Email</label>
<input type = "text" name="email" id="email" placeholder = "email address"></br></br>
<label for="password">Password</label>
<input type= "password" id="password" name="password"> </br></br>
<input type = "submit">
</form>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());

// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
}
</script>
</br></br></br>
<h1>Signup New User</h1>
<form action ="/signup" method="POST">
<label for="signup_email">Email</label>
<input type = "text" name="signup_email" id="signup_email" placeholder = "email address"></br></br>
<label for="signup_password">Password</label>
<input type= "password" id="signup_password" name="signup_password"></br></br>
<label for="signup_password_confirm">Confirm password</label>
<input type= "password" id="signup_password_confirm" name="signup_password_confirm"> </br></br>
<label for="signup_age">Age</label>
<input type = "text" id="signup_age" name ="signup_age" placeholder = "how old are you?"></br></br>
<label for="signup_gender">Gender</label>
<input type = "text" id="signup_gender" name ="signup_gender"></br></br>
<input type = "submit">
</form>
</body>
</html>

已解决,document.getElementById("mytext"(.value=;我的价值观;;

最新更新