JS 및 PHP를 기반으로하는 소규모 주문 페이지를 작성 중이며 양식 데이터를 처리하는 방법에 관해서 약간 고생했습니다. 양식에서 사용자는 하나 이상의 제품을 주문할 수 있어야하며 각 제품에는 라디오 버튼의 형태로 몇 가지 설정이 있습니다. 사용자가 하나 이상의 제품 부품을 추가하는 경우여러 양식 필드 그룹을 동적으로 작성하고 처리합니다.
newUnit = newUnit.replace(/name="unitPrice/g, 'name="unitPrice' + i);
newUnit = newUnit.replace(/name="body/g, 'name="body' + i);
newUnit = newUnit.replace(/name="details/g, 'name="details' + i);
newUnit = newUnit.replace(/name="topShelf/g, 'name="topShelf' + i);
<div class="unit">
<input type="hidden" class="unitPrice" name="unitPrice" value="0" data-price="6900">
<div class="row">
<div class="col-sm-3">
<fieldset class="form-group options-body">
<legend>Body</legend>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="0" name="body" value="White Ash" checked>
White Ash
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="0" name="body" value="Black Ash">
Black Ash
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="800" name="body" value="Walnut">
Walnut (+800)
</label>
</div>
</fieldset>
</div>
</div>
</div>
<div class="unit">
<input type="hidden" class="unitPrice" name="unitPrice" value="0" data-price="6900">
<div class="row">
<div class="col-sm-3">
<fieldset class="form-group options-body">
<legend>Body</legend>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="0" name="body2" value="White Ash" checked>
White Ash
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="0" name="body2" value="Black Ash">
Black Ash
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" data-price="800" name="body2" value="Walnut">
Walnut (+800)
</label>
</div>
</fieldset>
</div>
</div>
</div>
(샘플 태그 - 각 입력 필드를 고유하게하기 위해 I는 (새로운 제품을 추가하는 경우) 서로 다른 각 입력 이름값하게 작은 JS 조각을 첨가과 같이 실행중인 JS의)
이 방법은 주문 단계에서 가격과 설정을 업데이트하는 데 유용하지만 데이터를 제출할 때 다른 제품을 처리하는 방법이 확실하지 않습니다. 다른 이름. 이 아이디어, 방향에 대한 더 나은 접근 방법이 있습니까? 폼 데이터
unitPrice=6900&unitPrice=6900&body%5B%5D=White%20Ash&details%5B%5D=Stainless%20steel&topShelf%5B%5D=Wood&firstName=&lastName=&email=&phone=&address=&city=&zip=&country=&firstName2=&lastName2=&email2=&phone2=&address2=&city2=&zip2=&country2=&totalPrice=13800
코드 샘플이 필요하지 않습니다. 좋은 팁! –
그냥 도와 드리겠습니다. –
jquery.form.plugin - [link] (http://malsup.com/jquery/form/)을 보길 원할 것입니다. 양식 필드를 수정하기 전에 ' beforeSubmit' 옵션. –