82 lines
2.8 KiB
PHP
82 lines
2.8 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', 'Buat Pesanan')
|
|
|
|
@section('content')
|
|
<div class="container mt-4">
|
|
<h2 class="mb-3">Buat Pesanan</h2>
|
|
|
|
<form action="{{ route('pelanggans.store') }}" method="POST">
|
|
@csrf
|
|
|
|
<div class="mb-3">
|
|
<label>Nama Pemesan</label>
|
|
<input type="text" name="nama_pemesan" class="form-control" value="{{ old('nama_pemesan') }}" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>Email</label>
|
|
<input type="email" name="email" class="form-control" value="{{ old('email') }}" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>No. Telepon</label>
|
|
<input type="text" name="no_tlpn" class="form-control" value="{{ old('no_tlpn') }}" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label>Template</label>
|
|
<select name="template_id" id="template_id" class="form-select" required>
|
|
<option value="">-- Pilih Template --</option>
|
|
@foreach($templates as $template)
|
|
<option value="{{ $template->id }}" data-form='@json($template->form)'>
|
|
{{ $template->nama_template }} (Rp {{ number_format($template->harga,0,',','.') }})
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
|
|
<!-- tempat field dinamis -->
|
|
<div id="dynamic-form"></div>
|
|
|
|
<button type="submit" class="btn btn-success">Kirim Pesanan</button>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('template_id').addEventListener('change', function () {
|
|
let selected = this.options[this.selectedIndex];
|
|
let formJson = selected.getAttribute('data-form');
|
|
let container = document.getElementById('dynamic-form');
|
|
container.innerHTML = '';
|
|
|
|
if (formJson) {
|
|
let fields = JSON.parse(formJson);
|
|
for (let key in fields) {
|
|
let field = fields[key];
|
|
let label = field.label ?? key;
|
|
let input = '';
|
|
|
|
if (field.type === 'text') {
|
|
input = `<input type="text" name="form[${key}]" class="form-control" ${field.required ? 'required' : ''}>`;
|
|
} else if (field.type === 'textarea') {
|
|
input = `<textarea name="form[${key}]" class="form-control" ${field.required ? 'required' : ''}></textarea>`;
|
|
} else if (field.type === 'select') {
|
|
input = `<select name="form[${key}]" class="form-select">`;
|
|
field.options.forEach(opt => {
|
|
input += `<option value="${opt}">${opt}</option>`;
|
|
});
|
|
input += `</select>`;
|
|
}
|
|
container.innerHTML += `
|
|
<div class="mb-3">
|
|
<label>${label}</label>
|
|
${input}
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
@endsection
|