0

2 つの div (請求の詳細と配送の詳細) がある Web ページを作成しています。ページが読み込まれると、請求の詳細が自動的に表示され、配送の詳細は空のままになります。配送の詳細が請求の詳細と同じかどうかをユーザーが選択できるようにする 2 つのラジオ ボタンを含めました。ユーザーがラジオ ボタンから [はい] を選択すると、同じ詳細が配送の詳細に表示されます。注:詳細はデータベースに保存され、phpを使用してデータを表示しています

現時点では、私は使ってみただけです

<?php if(isset($_POST'[shipping'] == 'yes')){echo $fname} ?>

名のフィールドで、それが機能しているかどうかを確認するだけですが、機能していないようです。

<div id="leftprofile">
    <form id="au" method="post" action="../../../coursework/coursework/scripts/checkout.php">
    <fieldset class="billing">
        <legend>Billing Details</legend><br />
        <label for="fname" class="reglabel">First Name:</label>
        <input required name="fname" type="text" id="fname" value="<?php echo $fname ?>"/><br />
        <label for="lname" class="reglabel">Last Name:</label>
        <input required name="lname" type="text" id="lname" value="<?php echo $lname ?>"/><br />
        <label for="address" class="reglabel">Address:</label>
        <input required name="address" id="address" type="text" value="<?php echo $address ?>"/><br />
        <label for="town" class="reglabel">Town:</label>
        <input required name="town" id="town" type="text" value="<?php echo $town ?>"/><br />
        <label for="postcode" class="reglabel">Post Code:</label>
        <input required name="postcode" id="postcode" type="text" value="<?php echo $postcode ?>"/><br />
        <label for="phone" class="reglabel">Phone:</label>
        <input required name="phone" id="phone" type="text" value="<?php echo $phone ?>"/><br />
        <label for="email" id="EmailLabel" class="reglabel">E-mail:</label>
        <input required name="email" type="email" id="email" value="<?php echo $email ?>"/><br />
    </fieldset>
    </form>
</div>

<div id="rightprofile">
    <form id="au" method="post" action="../../../coursework/coursework/scripts/checkout.php">
    <fieldset class="billing">
        <legend>Shipping Details</legend><br />
        <form>
            Same as billing address?
            <input type="radio" name="shipping" id="yes" value="yes">Yes
            <input type="radio" name="shipping" id="no" value="no">No<br/>
        </form>
        <label for="fname" class="reglabel">First Name:</label>
        <input required name="fname" type="text" id="fname" value="<?php if(isset($_POST'[shipping'] == 'yes')){echo $fname} ?>"/><br />
        <label for="lname" class="reglabel">Last Name:</label>
        <input required name="lname" type="text" id="lname" /><br />
        <label for="address" class="reglabel">Address:</label>
        <input required name="address" id="address" type="text" /><br />
        <label for="town" class="reglabel">Town:</label>
        <input required name="town" id="town" type="text" /><br />
        <label for="postcode" class="reglabel">Post Code:</label>
        <input required name="postcode" id="postcode" type="text" /><br />
        <label for="phone" class="reglabel">Phone:</label>
        <input required name="phone" id="phone" type="text" /><br />
        <label for="email" id="EmailLabel" class="reglabel">E-mail:</label>
        <input required name="email" type="email" id="email" /><br />
    </fieldset>
    </form>
</div>
4

1 に答える 1

1

簡単なサンプルコードをいくつか書きました。このサイトには、2 つの入力フィールド (請求と配送) を含む 1 つのフォームと、配送情報が請求情報と同じかどうかを確認するためのチェックボックスが 1 つあります。チェックボックスがチェックされている場合、コードは「shipping」に入力されたものを単に無視します。

これは、少なくとも PHP の観点からは、あなたが求めていることを達成するでしょう。ブラウザで「これらの入力フィールドのデータをそれらの入力フィールドにリアルタイムでコピーする」ことをさらに探している場合、それはPHPではなくJavascriptのタスクです。

<?php
/* Check if anything was submitted */
if(isset($_POST))
{
    /* Retrieve billing information */
    $billing_name = $_POST['billing_name'];
    $billing_addr = $_POST['billing_addr'];

    /* Check if shipping same as billing */
    if(isset($_POST['same']))
    {
        /* Shipping is the same as billing */
        $shipping_name = $billing_name;
        $shipping_addr = $billing_addr;
    }
    /* If not, set shipping to the posted value */
    else
    {
        $shipping_name = $_POST['shipping_name'];
        $shipping_addr = $_POST['shipping_addr'];
    }

    $insert = mysql_query(...);
}
?>

<form method="post" action="#" />

Billing information
<label for="billing_name">Name</label>
<input type="text" id="billing_name" name="billing_name" />
<label for="billing_addr">Addr</label>
<input type="text" id="billing_addr" name="billing_addr" />

<label for="same" />Is the shipping information the same as billing information?</label>
<input type="checkbox" id="same" name="same" />

Shipping information
<label for="shipping_name">Name</label>
<input type="text" id="shipping_name" name="shipping_name" />
<label for="shipping_addr">Addr</label>
<input type="text" id="shipping_addr" name="shipping_addr" />

<input type="submit" value="Register" />

</form>
于 2013-04-01T21:54:38.060 に答える