php - NULL radio button value

622

On line 13 of my code, I am getting a NULL $NaN value. If I replace $_POST['amount'] with static integer, the code POST the correct value. But trying to add a little functionality, now I can't get data to pass???

http://i40.tinypic.com/34gxauw.png

<div id="container">
<?php
    require_once('stripe-php/lib/Stripe.php');
    $stripe = array(
    'secret_key' => 'sk_07C5ukIdqxyDGFqIKB8f7TXqGGyQt',
    'publishable_key' => 'pk_07C58BHnzuFYQr9AUoZD6SCLiwANw'
    );
    Stripe::setApiKey($stripe['secret_key']);

    if ($_POST) {
        $charge = Stripe_Charge::create(array(
            'card' => $_POST['stripeToken'],
            'amount' => $_POST['amount'],
            'currency' => 'usd'
        ));
        var_dump($_POST['amount']);
        $quotes = array(
            "Thank you for your purchase!",
            "Enjoy your experience with with us!"
        );

        echo "<h1>Here's your quote!</h1>";
        echo "<h2>".$quotes[array_rand($quotes)]."</h2>";
    }
    else {
?>

    <h2>TPC Holdings</h2>
    <h3>Select your campaign package!!</h3>

    <form>
        <fieldset>
            <legend>Select your package</legend>
            <p>
                <label>Select your package</label>
                <input type = "radio"
                        name = "amount[]"
                        id = "sizeSmall"
                        value = "50"
                        checked = "checked" />
                <label for = "sizeSmall">$50.00</label>

                <input type = "radio"
                        name = "amount[]"
                        id = "sizeMed"
                        value = "75" />
                <label for = "sizeMed">$75.00</label>

                <input type = "radio"
                        name = "amount[]"
                        id = "sizeLarge"
                        value = "large" />
                <label for = "sizeLarge">$100.00</label>
           </p>
       </fieldset>
    </form>

    <form action="paybill.php" method="post">
        <script src="https://button.stripe.com/v1/button.js"
             class="stripe-button"
             data-key="<?php echo $stripe['publishable_key']; ?>"
             data-amount="<?php echo $d_charge; ?>"
             data-description="TPC purchase"
             data-label="Buy"></script>
    </form>

<?php
  }
?>

</div><!-- #container -->
352

Answer

Solution:

Don't makeamount field as anarray User willselect only one from these.

Try this,

<p>
    <label>Select your package</label>
    <input type = "radio"
        name = "amount"
        id = "sizeSmall"
        value = "50"
        checked = "checked" />
    <label for = "sizeSmall">$50.00</label>

    <input type = "radio"
        name = "amount"
        id = "sizeMed"
        value = "75" />
    <label for = "sizeMed">$75.00</label>

    <input type = "radio"
        name = "amount"
        id = "sizeLarge"
        value = "large" />
    <label for = "sizeLarge">$100.00</label>
</p>
425

Answer

Solution:

You NAN issue is coming from yourvalue="large". It should bevalue="100" or whatever value you need it to be. I can only assume, how the value is handled, that your handler is expecting a number and not a string.

People are also looking for solutions to the problem: php - Appending URL parameter at every request only if parameter already exists to save opt-out option responsive design

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.