Skip to content

Commit 4a18855

Browse files
committed
hide the form submit button when there is no field
1 parent 60d57f1 commit 4a18855

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

resources/views/form.blade.php

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,57 @@
2222

2323
<div class="card bg-light mb-3">
2424
<div class="card-body">
25-
<form action="{{ route('submit.form') }}" method="post">
26-
@csrf
27-
<input type="hidden" name="form_id" value="{{ $form_id }}" />
28-
<input type="hidden" name="field_ids" value="{{ $field_ids }}" />
25+
@if(count($fields) > 0)
26+
<form action="{{ route('submit.form') }}" method="post">
27+
@csrf
28+
<input type="hidden" name="form_id" value="{{ $form_id }}" />
29+
<input type="hidden" name="field_ids" value="{{ $field_ids }}" />
2930

30-
@foreach($fields as $field)
31-
@php
32-
$options = $field->pivot->options? json_decode($field->pivot->options) : null;
33-
$field_name = 'field_' . $field->pivot->id;
34-
$id_for = 'input-fld-'. $loop->iteration;
35-
@endphp
31+
@foreach($fields as $field)
32+
@php
33+
$options = $field->pivot->options? json_decode($field->pivot->options) : null;
34+
$field_name = 'field_' . $field->pivot->id;
35+
$id_for = 'input-fld-'. $loop->iteration;
36+
@endphp
3637

37-
<div class="form-group">
38-
@if($options->label)
39-
<label for="{{ $id_for }}">{{ $options->label }}</label>
40-
@endif
38+
<div class="form-group">
39+
@if($options->label)
40+
<label for="{{ $id_for }}">{{ $options->label }}</label>
41+
@endif
4142

42-
@switch($field->field_type)
43-
@case("select")
44-
<select id="{{ $id_for }}" name={{ $field_name }} class="custom-select @error($field_name) is-invalid @enderror">
45-
<option value="">Choose...</option>
46-
@foreach(explode(",", $options->values) as $value)
47-
<option value="{{ trim($value) }}" {{ old($field_name) == trim($value)? "selected" : "" }}>{{ trim($value) }}</option>
48-
@endforeach
49-
</select>
50-
@break
43+
@switch($field->field_type)
44+
@case("select")
45+
<select id="{{ $id_for }}" name={{ $field_name }} class="custom-select @error($field_name) is-invalid @enderror">
46+
<option value="">Choose...</option>
47+
@foreach(explode(",", $options->values) as $value)
48+
<option value="{{ trim($value) }}" {{ old($field_name) == trim($value)? "selected" : "" }}>{{ trim($value) }}</option>
49+
@endforeach
50+
</select>
51+
@break
5152

52-
@case("textarea")
53-
<textarea class="form-control @error($field_name) is-invalid @enderror" id="{{ $id_for }}" name={{ $field_name }} rows={{ $options->rows }}>{{ old($field_name) }}</textarea>
54-
@break
53+
@case("textarea")
54+
<textarea class="form-control @error($field_name) is-invalid @enderror" id="{{ $id_for }}" name={{ $field_name }} rows={{ $options->rows }}>{{ old($field_name) }}</textarea>
55+
@break
5556

56-
@default
57-
<input type="{{ $options->type == "date" ? "text" : $options->type }}" class="form-control {{ $options->type == "date"? "datepicker" : "" }} @error($field_name) is-invalid @enderror" name={{ $field_name }} id="{{ $id_for }}" value="{{ old($field_name) }}" />
58-
@endswitch
57+
@default
58+
<input type="{{ $options->type == "date" ? "text" : $options->type }}" class="form-control {{ $options->type == "date"? "datepicker" : "" }} @error($field_name) is-invalid @enderror" name={{ $field_name }} id="{{ $id_for }}" value="{{ old($field_name) }}" />
59+
@endswitch
5960

60-
@error($field_name)
61-
<div class="invalid-feedback">
62-
{{ $errors->first($field_name) }}
63-
</div>
64-
@enderror
65-
</div>
66-
@endforeach
61+
@error($field_name)
62+
<div class="invalid-feedback">
63+
{{ $errors->first($field_name) }}
64+
</div>
65+
@enderror
66+
</div>
67+
@endforeach
6768

68-
<div class="form-group mt-4">
69-
<button type="submit" class="btn btn-primary">
70-
<i class="fa fa-paper-plane-o" aria-hidden="true"></i> Submit
71-
</button>
72-
</div>
73-
</form>
69+
<div class="form-group mt-4">
70+
<button type="submit" class="btn btn-primary">
71+
<i class="fa fa-paper-plane-o" aria-hidden="true"></i> Submit
72+
</button>
73+
</div>
74+
</form>
75+
@endif
7476
</div>
7577
</div>
7678
</div>

0 commit comments

Comments
 (0)