나는 동적 인 형식을 가지고 있습니다.동적 양식의 요소를 에코하는 방법은 무엇입니까?
사용자는 원하는대로 n 개의 필드를 만들 수 있습니다. 그는 형태
여기 코딩 ID
<form method="post" action="">
<label>Service</label>
<select name="service">
<option value="1">Purchase</option>
<option value="2">Sale</option>
<option value="3">Rent</option>
</select>
<label>Number of fields</label><input type="text" name="no_fields"><br>
<input type="submit" name="submit">
</form>
<?php
if($_POST['no_fields']>0)
{
?>
<form method="post" action="">
<?php
$j=$_POST['no_fields'];
$s=$_POST['service'];
for($i=1;$i<=$j;$i++)
{
?>
<?php echo $i.". "; ?>
<label>Name of the field : </label><input type="text" name="name_field[]">
<label>Type : </label>
<select name="type[]">
<option>text</option>
<option>textarea</option>
<option>button</option>
<option>radio buton</option>
<option>checkbox</option>
</select>
<br><br>
<?php
}
?>
<input type="hidden" name="serv_id" value="<?php echo $s; ?>">
<input type="hidden" name="loop" value="<?php echo $j; ?>">
<input type="submit" name="save" value="save">
</form>
<?php
}
if(isset($_POST['save']))
{
foreach($name_field as $v)
{
echo $v;
}
}
?>
I 양식의 요소를 에코 할의 요소 1,2,3,4 ... 수를 만들 수 있지만이 작업을 수행 할 수 없습니다입니다 . Plz 도와주세요.
'$ _POST'가 작성해야 대문자. – duri
@jhonraymos : 필드 이름에 $ i를 사용해야하는 이유는 무엇입니까? –
@ Ravneet'Abid '[이보십시오] (http://stackoverflow.com/questions/2203430/posting-form-fields-with-same-name-attribute) – StaticVariable