Combine a Table + Form

@SaranacLake here is the code used if you need to see what I did:

<?php
session_start();

if(isset($_SESSION['plan'])) {
    echo '<p>Current Stored Session Data</p><p>';
    print_r($_SESSION['plan']);
    echo '</p>';
}

$products = [
	'Plan A' => [
		'name' => 'Basic Plan',
		'cost' => 10,
		],
	'Plan B' => [
		'name' => 'Standard Plan',
		'cost' => 20,
		],
	'Plan C' => [
		'name' => 'Basic Plan',
		'cost' => 50,
		],
	];
 
if($_SERVER['REQUEST_METHOD'] == 'POST')
{

        $_SESSION['plan'] = $_POST['plan'];
    
         echo "You chose,\n Our {$products[$_POST['plan']]['name']} and that costs \${$products[$_POST['plan']]['cost']}";
    if(isset($_SESSION['plan'])) {
        echo '<p>After the last request Session Data</p><p>';
        print_r($_SESSION['plan']);
        echo '</p>';
    }
}
?>

<!doctype html>
<html>
    <head></head>
    <body>
        <form method='post'>
            <table>                
                <tr>
                    <td></td>
                    <td><input type='submit' name='plan' value='Plan A'></td>
                    <td><input type='submit' name='plan' value='Plan B'></td>
                    <td><input type='submit' name='plan' value='Plan C'></td>
                </tr>
                <tr>
                    <td>Free stuff</td>
                    <td>X</td>
                    <td>Y</td>
                    <td>Y</td>
                </tr>
                <tr>
                    <td>Account Access</td>
                    <td>Y</td>
                    <td>Y</td>
                    <td>Y</td>
                </tr>
                <tr>
                    <td>Cost</td>
                    <td>$10</td>
                    <td>$20</td>
                    <td>$50</td>
                </tr>                
            </table>
        </form>        
    </body>
</html>
1 Like

I am looking at the HTML now.

Thanks for the PHP code as well.

I know all of this seems very basic to someone like you, but when you haven’t done this in several years it seems hunormous!

I look forward to when I get my site up and then I can go back and study up on PHP, HTML, CSS from scrtahc. (And maybe even finally learn Javascript?!)

Thanks again!! :+1:

@astonecipher,

How do I get your example to work if all of my buttons are called “Select”?

For example…

<td><input type='submit' name='silver' value='Select'></td>
<td><input type='submit' name='gold' value='Select'></td>
<td><input type='submit' name='platinum' value='Select'></td>

Use an image for the button.

Is that my only option?

Can I use a hidden value?

How would you set the hidden value? If you do a separate submit button altogether, you could use radio buttons and make them look like a normal button.

You can submit a hidden value with a traditional form. But since I have 3 submit buttons, I don’t see how to map a hidden value to the button selected.

I actually started a new thread related to this…

https://www.phphelp.com/t/relay-price-to-checkout-page/28356

Sponsor our Newsletter | Privacy Policy | Terms of Service