<div id="roleList">
    <form id = "send-form" method="post" action="<?=$home_way?>/count_form.php/?p=form&sp=select">
        <div id="address-field">
            <div class="center-address-block">
                <div class="e-mail-block">
                    <p><label style="color: red">*</label> Email:</p>
                    <input type="text" id="email" name="email" >
                </div>

                <div class="text-block">
                    <p>Укажите, пожалуйста, ваше имя и телефон:</p>
                    <textarea name="comment" class="textarea-block" placeholder=""></textarea>
                </div>
                    <input type="submit" class="button_style" id="send-button" value="Отправить">
            </div>
        </div>
    <div id="questionnaire">
    <?php
    function showRole($array,$sub_array,$object,$key){
    $num=count($array);
    for($i=0; $i<$num; $i++){
    if($array[$i]['parent_id']==$key){
    if($key == 0){?>
        <div class="back-office-block">
            <ul>
                <li>
                    <label class="label_<?=$array[$i]['input_type']?>" for="input_<?=$array[$i]['id']?>" ><input id="input_<?=$array[$i]['id']?>" type="<?=$array[$i]['input_type']?>" class="form-input" <?= $array[$i]['required']?'checked':'' ?> data-parent = "<?=$array[$i]['id']?>" name="role[<?=$array[$i]['parent_id']?>][]" value="<?=$array[$i]['id']?>"> <?=$array[$i]['text']?></label>
                    <?php   if($sub_question = $object->findSubQuestion($array[$i],$sub_array)){?>
                    <div class="additional-question" data-key="<?= $sub_question['key_num'] ? $sub_question['key_num']:'' ?>" data-status="none">
                        <p><?= $sub_question['text']?></p>
                        <?php if($sub_question['input']=='textarea'):?>
                            <textarea class= "<?= $sub_question['required']?'required':'' ?>" id="question<?=$array[$i]['id']?>" name="question[<?=$array[$i]['id']?>]" > </textarea><?= $sub_question['required']?'<label class="required-label" for="question['.$array[$i]['id'].']">поле обязательно для заполнения</label>':'' ?>
                        <?php elseif($sub_question['input']=='text'):?>
                            <input type="text" class = "<?= $sub_question['required']?'required':'' ?>" value="" id="question<?=$array[$i]['id']?>" name="question[<?=$array[$i]['id']?>]"><?= $sub_question['required']?'<label class="required-label" for="question['.$array[$i]['id'].']">поле обязательно для заполнения</label>':'' ?>
                    </div>
                    <?php
                        endif;
                    }
                    $key=$array[$i]['id'];
                    showRole($array,$sub_array,$object,$key);
                    $key = $array[$i]['parent_id'];
                    ?>
                </li>
            </ul>
        </div>
    <?php } else { ?>
    <ul class="sub-elements">
        <li>
            <label class="label_<?=$array[$i]['input_type']?>" for="input_<?=$array[$i]['id']?>" ><input id="input_<?=$array[$i]['id']?>"  type="<?=$array[$i]['input_type']?>" class= "form-input"  <?= $array[$i]['required']?'checked':'' ?> data-parent = "<?=$array[$i]['id']?>" name="role[<?=$array[$i]['parent_id']?>][]" value="<?=$array[$i]['id']?>"> <?=$array[$i]['text']?></label>
            <?php  if($sub_question = $object->findSubQuestion($array[$i],$sub_array)){?>
            <div  class="additional-question" data-key="<?= $sub_question['key_num'] ? $sub_question['key_num']:'' ?>" data-status="none">
                <p><?= $sub_question['text']?></p>
                <?php if($sub_question['input']=='textarea'):?>
                    <textarea class= "<?= $sub_question['required']?'required':'' ?>" id="question<?=$array[$i]['id']?>" name="question[<?=$array[$i]['id']?>]" > </textarea><?= $sub_question['required']?'<label class="required-label" for="question['.$array[$i]['id'].']">поле обязательно для заполнения</label>':'' ?>
                <?php elseif($sub_question['input']=='text'):?>
                    <input type="text" class = "<?= $sub_question['required']?'required':'' ?>" id="question<?=$array[$i]['id']?>" value="" name="question[<?=$array[$i]['id']?>]"><?= $sub_question['required']?'<label class="required-label" for="question['.$array[$i]['id'].']">поле обязательно для заполнения</label>':'' ?>
            </div>
                <?php
                endif;
            }
            $key=$array[$i]['id'];
            showRole($array,$sub_array,$object,$key);
            $key = $array[$i]['parent_id'];
            echo "</li>";
            echo "</ul>";
            }
            }
            }
            }
            $key=0;
            showRole($data['data'],$data['sub_data'],$object,$key);
        ?>
            <p class="button_style" id="next-button">Рассчитать стоимость</p>
    </div>


    </form>
</div>
