Last active
August 31, 2023 06:11
-
-
Save hkkcngz/37ba998171686ab576c54468578f1ed1 to your computer and use it in GitHub Desktop.
Bootstrap Modal Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateModal($modalId, $modalTitle, $fields, $extraHtml = "") { | |
$submitButtonId = $modalId . "Submit"; | |
$submitButtonText = 'Kaydet'; | |
$modal = '<div class="modal fade" id="' . $modalId . '" tabindex="-1" role="dialog" aria-labelledby="' . $modalId . 'Label" aria-hidden="true"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title">' . $modalTitle . '</h5> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Kapat"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
<div class="modal-body">'; | |
foreach($fields as $field) { | |
if($field['type'] != 'hidden') { | |
$modal .= '<div class="mb-1"> | |
<label for="' . $field['id'] . '" class="form-label">' . $field['label'] . '</label>'; | |
} | |
if($field['type'] == 'text' || $field['type'] == 'hidden') { | |
$modal .= '<input type="' . $field['type'] . '" class="form-control" id="' . $field['id'] . '" placeholder="' . ($field['label'] ?? '') . '">'; | |
} else if($field['type'] == 'select') { | |
$modal .= '<select class="form-control" id="' . $field['id'] . '">'; | |
foreach($field['options'] as $optionValue => $optionText) { | |
$modal .= '<option value="' . $optionValue . '">' . $optionText . '</option>'; | |
} | |
$modal .= '</select>'; | |
} else { | |
$modal .= '<input type="' . $field['type'] . '" class="form-control" id="' . $field['id'] . '" placeholder="' . ($field['label'] ?? '') . '">'; | |
} | |
if($field['type'] != 'hidden') { | |
$modal .= '</div>'; | |
} | |
} | |
$modal .= $extraHtml; | |
$modal .= '</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-secondary" data-dismiss="modal">İptal</button> | |
<button type="button" class="btn btn-primary" id="' . $submitButtonId . '">' . $submitButtonText . '</button> | |
</div> | |
</div> | |
</div> | |
</div>'; | |
return $modal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment