2013-04-01 12 views
0

두 개의 div (결제 세부 정보 및 배송 세부 정보)가있는 웹 페이지를 만듭니다. 페이지가로드되면 청구 세부 사항이 자동으로 표시되고 운송 세부 사항은 비어 있습니다. 두 개의 라디오 버튼을 포함하여 배송 세부 정보가 결제 세부 정보와 동일한 지 여부를 사용자가 선택할 수 있습니다. 사용자가 단일 선택 단추에서 예를 선택하면 동일한 세부 사항이 운송 세부 사항에 표시됩니다. 참고 : 자세한 내용은 데이터가 순간라디오 버튼을 클릭 할 때 텍스트 필드를 채우는 방법?

를 표시 얻기 위해 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> 
+1

글쎄, 결제 및 배송 또는 동일한 입력의 이름이므로 제출 된 양식을 최종적으로 얻을 때 문제가 발생합니다. 또한 양식을 제출하기 전에 처리해야하므로 Javascript로 작성해야합니다. (또한 한 번에 하나의 양식 만 제출할 수 있습니다. 두 곳 모두 동일한 위치로 제출하는 두 가지 양식이 있습니다.) – Jon

+0

다른 div이지만 텍스트 필드가 동일합니다 – littledevils326

+0

정확하게 내 포인트. 모두가 동일한 '조치'에 제출 될 경우 청구 및 운송 필드 '이름'을 구별해야합니다. – Jon

답변

1

간단한 예제 코드를 작성했습니다. 이 사이트에는 입력란 2 개 (청구 및 배송)와 배송 정보가 결제 정보와 동일한 지 확인하는 하나의 확인란이있는 양식이 하나 있습니다. 확인란을 선택하면 코드가 '배송'에 입력 한 내용을 무시합니다.

이것은 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> 
관련 문제