Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting value of clicked element in PHP

I have a page with element <a> acting like a <button>, in this form the elements works like a service plans, and i want to get a value when one of these buttons has been clicked.

Page1.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page 1</title>
    <?php
    session_start();
    ?>
</head>
    <body>

        <section>
            <a href="page2.php" value='basic' name="plan">Choose Plan1</a>
            <br><br>
            <a href="page2.php" value='intermediary' name="plan">Choose Plan2</a>
            <br><br>
            <a href="page2.php" value='premium' name="plan">Choose Plan3</a>
        </section>

    </body>
</html>

Page2.php

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php
session_start();
echo 'test';
echo $_POST['name'];
?>

I know that $_POST['name'] doesn’t works cuz don’t exist a input, but i don’t know how use something like this to get a value of button clicked and show this value.

The return expected for first button for example, is something like:

basic

I need this value to put in database after.

Someone can help me to get this values?

>Solution :

You may pass the value as a url parameter

        <section>
            <a href="page2.php?plan=basic" >Choose Plan1</a>
            <br><br>
            <a href="page2.php?plan=intermediary">Choose Plan2</a>
            <br><br>
            <a href="page2.php?plan=premium">Choose Plan3</a>
        </section>

And get it from $_GET in your php code

echo $_GET['plan'];

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading