I'm trying to return html, to my ajax request. The ajax request requests a controller method to create a view according to what is clicked.
It's a simple form. But it should have a <select> tag in it.
The <select> tag should display different roles, with one role already selected. which can be assigned to different users.
So I tried creating an object as so:
$roles = $this->database->GetAllRoles();
$selectedRole = $this->database->GetAllRoles()->where('id', '=', $user->roles_id)->first();
foreach($roles as $role){
$selectObject =
'
<option selected value="' . $selectedRole['id'] . '">"' . $selectedRole['name'] . '"</option>
<option value="' . $roles->id . '">"' . $roles->name . '"</option>
';
}
$htmlFinal =
'
<form>
<!-- Form labels and inputs ... -->
<select class="form-control" type="text">
"' . $selectObject . '"
';
This is what it should look like, with a selected option in the form select tag, and more options when opened.
Obviously the above code doesn't work ofcourse, I tried alot of different approaches but I'm kind of stuck right now.