• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Possible to parse a variable to the snippet on the same page?

Messages
1
Likes
0
Points
1
#1
Hello,

I am trying to collect information from a user within a page, is there a way to take the data that they input and then use that in the code snippet?

For example, asking a user for their name, taking that name and then saying a message along the lines of "hello, user"

I have a variable in my php called test, I would like to fill that variable with the information the user gives me.

Sorry if this seems like a simple question :)
 

Attachments

Kirill

Support team
Messages
82
Likes
4
Points
8
#2
Hello

Create a form so that the user can enter data.
The submitted data will be stored in the $_POST global array.

Here is a simple example.
PHP:
if(isset($_POST['user_name'])){
    $test = $_POST['user_name'];
    echo "<h2>Hello " . esc_html($test) . "</h2>";
}else{
    ?>
    <form action="" method="post">
        <label>Your name:</label>
        <input type="text" name="user_name">
        <button type="submit">Send</button>
    </form>
    <?php
}
Please note that the data received from users should be sanitized and validated. Otherwise it may become a vulnerability to hacking attacks. Read more

Best regards