I am a beginner with Yii and I am uncertain if I am making mistakes in my implementation. I am attempting to iterate through an array of remote search forms and display the relevant form in the innerHTML based on the user’s selected search type. However, when I include the PHP form render in the array, none of my remaining innerHTML elements show up, and the forms fail to render. They work perfectly fine in HTML, but issues arise when I try to display them via JavaScript. Can anyone provide guidance on this? Below is my code:
View:
div class='search-tabs-new animated fadeInUp'>
<!-- Selector for search method (by Person, Phone, or Address) -->
<div class='home-search-custom-select'>
<ul class='home-search-method-options-list'>
<li id='home-search-by-btn'>Select Search Option...</li>
<li class='home-search-method-option'></li>
<li class='home-search-method-option'></li>
<li class='home-search-method-option'></li>
</ul>
</div>
<div id='home-search-form-area'>
</div>
JavaScript:
let searchOptions = [
'Phone Number',
'Name',
'Address'
];
let searchForms = [
'<?= $this->render('/site/forms/phone_search', ['uri' => Url::to(['phone/process'])]); ?>',
'<?= $this->render('/site/forms/person_search', ['uri' => Url::to(['people/process'])]); ?>',
'<?= $this->render('/site/forms/address_search', ['uri' => Url::to(['address/process'])]); ?>'
];
let methodOptions = document.querySelectorAll('.home-search-method-option');
methodOptions = Array.from(methodOptions);
function initializeSearchMethods() {
for (let index = 0; index < methodOptions.length; index++) {
const option = methodOptions[index];
const searchType = searchOptions[index];
const currentForm = searchForms[index];
option.innerHTML = searchType;
option.addEventListener('click', function() {
document.getElementById('home-search-form-area').innerHTML = currentForm;
});
}
}
initializeSearchMethods();