[英]How can I make my anchor tag transfer information from my table?
I have an anchor tag that displays a users name and clicked it is supposed take you to their profile page. 我有一个显示用户名的锚标记,然后单击它可以将您带到他们的个人资料页面。 I created a form with a post method that I need for accessing that users profile. 我创建了带有post方法的表单,该表单是我访问该用户个人资料所需的。 How can I make the anchor tag act as the form? 如何使锚标签充当表单?
I need the post method with the form to access that user's profile page. 我需要带有表单的post方法来访问该用户的个人资料页面。 $post is a varaible from a foreach loop. $ post是foreach循环中的变量。
<a href = "profiles.php" id = "name1"><h1>'.$post["UserID"].'</h1></a>
<form action = "profiles.php" method = "POST" >
<input type="submit" class="post id= "nameid" name="id" value= "'.$post["UserID"].'">
</form>
Unless you handle the link with client-side code instead of just letting it be a link, you can't. 除非您使用客户端代码处理链接,而不仅仅是让它成为链接,否则您将无法这样做。
The anchor will send a GET request, while your form is sending a POST request. 当您的表单正在发送POST请求时,锚将发送GET请求。
If you're okay with that, you can append the user id to the query string in the href. 如果可以,可以将用户ID附加到href中的查询字符串中。
'<a href="profiles.php?id='.$post["UserID"].'" id="name1"><h1>'.$post["UserID"].'</h1></a>'
Then you can get the id from $_GET['id']
in profiles.php. 然后,您可以从profiles.php中的$_GET['id']
获取ID。 That may not be what you want to do if you don't want the user id in the URL. 如果您不想在URL中输入用户ID,那可能就不是您想要的。 In my opinion would be fine though, and maybe even preferable. 我认为这会很好,甚至更可取。 That would make it easier for a user to bookmark their profile. 这将使用户更容易为他们的个人资料添加书签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.