admin管理员组文章数量:1302429
I have a sign up form on my homepage and would like to capture the user's entries and have them populated into the customer registration form on a new page.
Is there a way to do this in WordPress?
I have a sign up form on my homepage and would like to capture the user's entries and have them populated into the customer registration form on a new page.
Is there a way to do this in WordPress?
Share Improve this question edited Mar 26, 2021 at 14:02 Dave Romsey 17.9k11 gold badges56 silver badges70 bronze badges asked Mar 26, 2021 at 6:55 Urick EsauUrick Esau 1 2- 2 Hey @Urick that's a great question. However it's not one you can solve with a click of a button. You can pass the variables from URL and GET them in the registration form on the new page. That is not the method if you are passing passwords though. In that case maybe you have to save them in a superglobal, like session. – billybadass Commented Mar 26, 2021 at 9:10
- 3 What have you tried so far? Can we see the code you've written? – Andy Macaulay-Brook Commented Mar 26, 2021 at 10:01
1 Answer
Reset to default 0While this is not a WordPress specific problem it is not a non-WordPress problem either. It sounds like you need a little guidance on how forms pass data.
If what you are really asking is how to get a plugin to pre-populate a form, you are best off asking the plugin's developer.
Assuming that you want to do this yourself, here is a primer on things you will need to know.
There are two (that we are going to talk about) ways for a form to send data. These are the GET request and the POST request.
Let's start with a field, we shall call it foo.
<form method="get">
<label for="foo">Foo</label><input type="text" value="" name="foo" />
<input type="submit" value="submit">
</form>
You will notice that I set the method to get. That means that the form data (foo) will be added to the end of the URL. It might look like this if the user typed "bar":
https://example/myform.php?foo=bar
Your users' data will be found in $_GET['foo']
. However, you need to check if it exists.
if(isset($_GET['foo'])){
$foo = $_GET['foo']; // or whatever
}
The advantage of GET is that users can share links with the data in them. The disadvantage is that users can share links with the data in them. (It depends on what you need to do with it).
The other way is to use POST. Like this:
<form method="post">
<label for="foo">Foo</label><input type="text" value="" name="foo" />
<input type="submit" value="submit">
</form>
Notice that the method in the form has changed. This page has a guide to form methods. Now the form data will be sent using the post method (not in the URL) and can be accessed via the POST global.
if(isset($_POST['foo'])){
$foo = $_POST['foo']; // or whatever
}
So now you want to put this data in another form. Here is how you might do it.
<?php
// other code maybe
$foo = '';
if(isset($_POST['foo'])){
$foo = $_POST['foo'];
}
?>
<form method="post">
<label for="foo">Foo</label><input type="text" value="<?php echo $foo; ?>" name="foo" />
<input type="submit" value="submit">
</form>
In this last example, I made an empty var called $foo. If the user sent us a foo in the POST, I added the value to the new var. Then I spat it out in the form. This way the form is pre-filled with the foo we just got.
Note: This is not an inherently safe way to do things. A bad actor could send you bad code that could break your form or even your entire site. Take a look at WordPress string sanitisation functions.
For example:
if(isset($_POST['foo'])){
$foo = sanitize_text_field($_POST['foo']);
}
That is much safer.
You should now have some understanding of how forms pass information. If you are creating your own forms, this could be useful to you.
At the very least, this should get you started. You can always come back with more specific questions if you get stuck a little further on.
本文标签: postsHow can I pass form entry to another form on a new page
版权声明:本文标题:posts - How can I pass form entry to another form on a new page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741651755a2390520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论