0

我正在用 django 创建一个信用卡支付页面。用户可以选择填写信用卡信息或使用之前输入的卡。然而,用户必须选择一个位置。

有没有办法创建表单,所以我不必有 2 个单独的位置“选择”按钮?

HTML:

    <h1>Charge $10 with Stripe</h1>
    <!-- to display errors returned by createToken -->
    <span class="payment-errors"></span>
    <form action="" method="POST" id="payment-form">
        {% csrf_token %}

        {% if not user.is_authenticated %}

        <div class="form-row">
            <label>Full Name</label>
            <input type="text" size="30" autocomplete="off" name="fullname" />
        </div>
        <div class="form-row">
            <label>Email</label>
            <input type="text" size="30" autocomplete="off" name="email" />
        </div>
        <div class="form-row">
            <label>Phone</label>
            <input type="text" size="11" autocomplete="off" name="phone" />
        </div>

        {% endif %}
        <label>Location</label>
        <select name="location">
        <option value="muir">Muir</option>
        <option value="erc">ERC</option>
        <option value="marshall">Marshall</option>
        <option value="warren">Warren</option>
        <option value="revelle">Revelle</option>
        <option value="sixth">Sixth</option>

        </select>

        <div class="form-row">
            <label>Card Number</label>
            <input type="text" size="20" autocomplete="off" class="card-number" />
        </div>
        <div class="form-row">
            <label>CVC</label>
            <input type="text" size="4" autocomplete="off" class="card-cvc" />
        </div>
        <div class="form-row">
            <label>Expiration (MM/YYYY)</label>
            <input type="text" size="2" class="card-expiry-month"/>
            <span> / </span>
            <input type="text" size="4" class="card-expiry-year"/>
        </div>
        {% if user.is_authenticated %}
        <input type="checkbox" name="save_card_info" value="yes"/> Save this card </br>
        {% endif %}
        <button type="submit" class="submit-button">Submit Payment</button>
    </form>

    {% if user.is_authenticated and user.get_profile.stripe_customer_id %}
    </br>
    OR:
    </br>
    </br>
    Use card ending with: 4343
    <form action="" method="POST">
        {% csrf_token %}

        <label>Location</label>
        <select name="location">
        <option value="muir">Muir</option>
        <option value="erc">ERC</option>
        <option value="marshall">Marshall</option>
        <option value="warren">Warren</option>
        <option value="revelle">Revelle</option>
        <option value="sixth">Sixth</option>
        </select>
        </br>
        <input type="hidden" name="action=" value="pay_saved_card"/>
        <button type="submit">Submit Payment</button>

    </form>
    {% endif %}
</body>
4

1 回答 1

0

您可以在相应表单的提交事件处理程序中通过 JavaScript(使用 jQuery 时可能很容易)检索选定的位置。

于 2012-09-07T06:48:58.907 回答