Dropzone sending all queue of uploaded files to the controller once - php

I am trying to send multiple files in one request using DropZone js.
<script type="text/javascript">
Dropzone.autoDiscover = false;
var file= new Dropzone(".dropzone",{
url: any url,
method:"post",
paramName:"PhotoFiles",
addRemoveLinks:true,
autoProcessQueue: false
});
//Upload file onsubmit
$('#UploadMultiFiles').submit(function(){
file.processQueue();
});
file.on("sending",function(a,b,c){
a.token=Math.random();
c.append("token",a.token);
});
The issue is I have other inputs in the same form that is why I used onsubmit, and these inputs are saved in a table and the images from dropzone are saved in another table with and both tables have one to many relationship
The Controller like:
public function university_offers($id){
$data['university_offer_name']=$this->input->post('university_offer_name');
$data['university_id_fk']=$this->input->post('university_id_fk');
$data['university_offer_details']=$this->input->post('university_offer_details');
if ($this->input->post('save')){
$data2['university_offer_id_fk'] = insertrecords('university_offers',$data);
$data2['university_id_fk'] = $data['university_id_fk'];
//when I put the next IF at the begining of the function it works but ofcourse without the other data fields that I need.
if(isset($_FILES) && $_FILES != null){
$data2['photo_name'] = upload_image('PhotoFiles');
insertrecords('university_offer_photos',$data2);
}
if (insertrecords('university_offer_photos',$data2)==true)
message('success','');
redirect('Admin/university_offers/0','refresh');
}
$data['view']="admin/universities/university_offers";
$this->load->view('index',$data);
}
What I need is sending al uploaded files and do a loop in the controller to save it right in the database, not sending each file to the controller and saving it.
Edit:
My view is like:
<form action="university_offers/<?=$id?>" id="UploadMultiFiles" autocomplete="off" method="post" enctype="multipart/form-data" class="m-t-5" novalidate>
<div class="form-body">
<h3 class="card-title">بيانات العرض</h3>
<hr>
<div class="row p-t-20">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم العرض<span class="text-danger">*</span></label>
<div class="controls">
<input type="text" autocomplete="off" name="university_offer_name" class="form-control" required value="<?php if(isset($result)) echo $result['university_offer_name']?>" data-validation-required-message="يجب إدخال إسم العرض" placeholder="إسم العرض">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم الجامعة<span class="text-danger">*</span></label>
<div class="controls">
<select name="university_id_fk" id="select" class="form-control" required data-validation-required-message="يجب إختيار الجامعة" aria-invalid="false">
<option value="">إختر الجامعة</option>
<?php
foreach (selectrecords("*",'universities') as $university):
$select = '';
if(isset($result) && $result['university_id_fk'] == $university->university_id_pk)
$select = 'selected';
?>
<option <?=$select?> value="<?php echo $university->university_id_pk ?>"><?php echo $university->university_name ?></option>
<?php endforeach;?>
</select>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">تفاصيل العرض<span class="text-danger">*</span></label>
<div class="controls">
<textarea id="mymce" name="university_offer_details"><?php if(isset($result)) echo $result['university_offer_details'] ?></textarea>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">صور العرض<span class="text-danger">*</span></label>
<div class="row">
<?php
if(isset($result)) {
foreach (selectrecords('*','university_offer_photos',array('university_offer_id_fk'=>$result['university_offer_id_pk'])) as $photo):
echo'
<div class="form-group text-center" id="'.$photo->photo_id_pk.'">
<div class="col-md-12">
<img style="border: none; height: 150px; width: 150px; border-radius: 10px;" class="img-thumbnail" src="'.base_url().'public/uploads/images/'.$photo->photo_name.'">
</div>
حذف الملف
</div>
';
endforeach;
}
?>
</div>
<div class="dropzone">
<div class="dz-message">
<span> Drag and Drop your files here Or Click here to upload</span>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions">
<input type="hidden" id="url" value="university_offers/<?=$id?>" />
<?php
if($id == 0)
echo '<button type="submit" id="butt" name="save" value="save" class="btn btn-primary"> <i class="fa fa-check"></i> حفظ</button>';
else
echo '<button type="submit" id="butt" name="edit" value="edit" class="btn btn-primary"><i class="fa fa-check"></i> حفظ</button>';
?>
<button type="reset" class="btn btn-inverse"><i class="fa fa-times"></i> إلغاء</button>
<?php
if($id == 0)
echo'<button type="button" id="backword" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
else{
echo '<input type="hidden" name="university_offer_id_pk" value="'.$result['university_offer_id_pk'].'"/>
<button type="button" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
}
?>
</div>
</div>
</form>
upload_image function, I put it in the Helper
function upload_image($file_name){
$CI =& get_instance();
$config['upload_path'] = 'public/uploads/images';
$config['allowed_types'] = 'gif|Gif|ico|ICO|jpg|JPG|jpeg|JPEG|BNG|png|PNG|bmp|BMP|WMV|wmv|MP3|mp3|FLV|flv|SWF|swf';
$config['max_size'] = '1024*8';
$config['encrypt_name']=true;
$CI->load->library('upload',$config);
if(! $CI->upload->do_upload($file_name)){
return false;
}else{
$datafile = $CI->upload->data();
thumb($datafile);
watermark($datafile);
return $datafile['file_name'];
}}

Related

jquery repeater taking last data record when added

using for each loop I have to retrieve data however when adding new record data-repeater-create is taking default value as the last record of data even the element id is different.
<div data-repeater-list="car">
<?php foreach ($user_portfolio as $p_details) {
$p_title = $p_details['portfolio_title'];
$p_desc=$p_details['portfolio_desc'];
$p_expert = $p_details['portfolio_expert_id'];
$p_id = $p_details['portfolio_id'];
?>
<div data-repeater-item>
<div class="form row">
<div class="form-group mb-1 col-sm-12 col-md-12">
<label for="email-addr">Title</label>
<br>
<input type="text" name="port_id" value="<?php if(!empty($p_id)) {echo $p_id; } else { echo "";}?>">
<input type="text" class="form-control" id="portfolio_title<?php echo $p_id;?>" placeholder="Title " name="portfolio_title" value="<?php if(!empty($p_title)) {echo $p_title;} else {echo ""; }?>">
</div>```
below using data-repeater-create i am adding empty field however its taking last record as default value and I able to see in view source
``` <?php } //end of foreach?>
</div>
<div class="form-group overflow-hidden">
<div class="col-12">
<button data-repeater-create class="btn btn-theme" type="button">
<i class="ft-plus"></i> Add
</button>
<button type="submit" class="btn btn-theme">
<i class="la la-check-square-o"></i> Save
</button>
</div>
</div>
</form>```

file upload error messages are not displaying in codeigniter

I'm trying to insert data into database through a form. I'm uploading 2 image files, in database path of the files will be stored. I'm trying to do server side validation. when user does not upload a file or when user is uploading wrong file type, an error messages should display and page should return to same page with no data inserted into database.
This is my view:
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-md-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Add News & Event</h4>
<p class="card-description"> </p>
<?php echo validation_errors("<div class='alert alert-danger'>","</div>");?>
<?php if($failed = $this->session->flashdata('addNewsFailed')){
echo '<div class="alert alert-danger">' ;
echo $failed;
echo '</div>';
}?>
<form class="forms-sample" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputName1">Title</label>
<input type="text" class="form-control" id="exampleInputName1" value="<?php echo
set_value("title");?>" name="title">
</div>
<div class="form-group">
<label for="exampleInputName1">Sub Title</label>
<input type="text" class="form-control" id="exampleInputName1" value="<?php echo set_value("sub");?>" name="sub_title">
</div>
<div class="form-group">
<label for="exampleInputName1">Event Date</label>
<input type="text" class="form-control" id="exampleInputName1" name="date" value="<?php echo date('d - M - y ');//echo set_value("date");?>">
</div>
<div class="container">
<div class="row">
<div class="col-md">
<div class="form-group">
<label>Feature Image</label>
<div class="input-group col-xs-12">
<input type="file" class="form-control file-upload-info" placeholder="Upload Image" name="img" style="z-index: 9999; opacity: 0;" id="image">
<div id="imageName"></div>
<span class="input-group-append">
<button class="file-upload-browse btn btn-info" type="button" style="position: absolute; left: 0; padding: 6px 23px;border-radius:3px;">Upload</button> </span>
</div>
<?php if(isset($upload_error)){
echo $upload_error;
}?>
</div>
</div>
<div class="col-md">
<div class="form-group">
<label> Banner Image</label>
<div class="input-group col-xs-12">
<input type="file" class="form-control file-upload-info" placeholder="Upload Image" name="banner" id="banner" style="opacity: 0; z-index: 9999;">
<div id="bannerName"></div>
<span class="input-group-append">
<button class="file-upload-browse btn btn-info" type="button" style="position: absolute;left: 0;padding: 6px 23px;border-radius: 3px;">Upload</button></span>
</div>
<?php if(isset($upload_error1)){
echo $upload_error1;
}?>
</div>
</div>
</div>
</div>
<span class="input-group-append">-->
<div class="form-group">
<label for="exampleTextarea1">Text</label>
<textarea class="form-control" id="exampleTextarea1" rows="2" name="para" value=""><?php echo set_value("para");?></textarea>
</div>
<button type="submit" class="btn btn-success mr-2">Add</button>
<button class="btn btn-light">Cancel</button>
</form>
</div>
</div>
</div>
</div>
</div>
This is my controller:
public function addEvent()
{
//load library
$this->load->library('form_validation');
$this->load->helper('form');
//set rules for validation
$this->form_validation->set_rules("title", "Title", "required");
$this->form_validation->set_rules("date", "Event Date", "required");
$this->form_validation->set_rules("para", "Text", "required");
//template
$this->output->set_template('admin_layout');
//image upload
$config = [
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
];
$this->load->library('upload', $config);
//validation
if ($this->form_validation->run()) {
$post = $this->input->post();
if (!$this->upload->do_upload('img')) {
$upload_error = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error'));
} else {
$Feature1 = $this->upload->data();
$image_path = base_url('uploads/' . $Feature1['raw_name'] . $Feature1['file_ext']);
$post['image_path'] = $image_path;
}
if (!$this->upload->do_upload('banner')) {
$upload_error1 = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error1'));
} else {
$carsousel = $this->upload->data();
$banner = base_url('uploads/' . $carsousel['raw_name'] . $carsousel['file_ext']);
$post['banner'] = $banner;
}
$this->load->model('loginmodel', 'addNews');
$insert_id = $this->addNews->addNews($post);
if ($insert_id) {
$this->session->set_flashdata("addNewsSuccess", 'News & Event Added Successfully');
redirect('dashboard/update_news/' . $insert_id);
} else {
$this->session->set_flashdata("addNewsFailed", 'Failed');
$this->load->view('dashboard/pages/forms/addEvent');
}
} else {
$upload_error = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error'));
}
}
This is my model:
public function addNews($array)
{
$this->db->insert('news', $array);
return $this->db->insert_id();
}
My form validation are working perfectly but when user is uploading wrong file type or does not upload any file then file upload error message is not displaying and data is inserting into database the with both image field empty.

Want To Exec command To Solr

this Is My Code In View
<form class="form-horizontal" id="USER_ID_LOGING" name="USER_ID_LOGIN" action="<?php echo base_url('feed_admin/feed_submit') ?>" method="POST">
<div class="form-group">
<label for="inputPass" class="col-sm-1 control-label">Feed</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="input_feed" name="input_feed" value="<?php echo set_value('input_feed'); ?>" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
<button type="submit" class="btn btn-success"> input Feed </button>
</div>
</div>
</form>
this is controller
function feed_submit(){
$this->form_validation->set_rules('input_feed','feed','required');
if($this->form_validation->run() == true)
{
$feedlink = $this->input->post("input_feed");
$solr_check ="dir";
$solr_directory="cd C:\solr";
$solr_dir = passthru("$solr_directory $solr_check" );
echo $solr_dir;
}
My Problem Is I want To execute Command To Cd To Another Floder like This
cd C:\solr and add new feed To solr
Thank you For your answer

Codeigniter multiple form in one page with separate validation

I have two form in one page. When I click on the submit button of form one, the validation error shows on both forms. How could show separate validation errors on each form?
This is my view:
<?php echo form_open('user_signup/login',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
This is my controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
if ($this->input->post('submit_form')) {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
else if ($this->input->post('register_form')) {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if (!$this->form_validation->run()) {
$this->load->view('User/signup');
}
else {
if ($this->input->post('submit_form'))
echo 'Form 1 posted !';
else if ($this->input->post('register_form'))
echo 'Form 2 posted !';
}
}
}
There are two things you need to concern about that. First passing action in HTML form. Second is, getting those parameters and code accordingly in your controller's action.
<?php echo form_open('user_signup/login/form-1',['class'=>'login-form','id'=>'submit_form']);
echo validation_errors();?>
<h3 class="form-title font-green">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email1','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email1')]); ?>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<?php echo form_input(['name'=>'pass','type'=>'password','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Password']); ?>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Submit',"class='btn green uppercase'" ); ?>
Forgot Password?
</div>
<div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
</li>
<li>
<a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
</li>
</ul>
</div>
<div class="create-account">
<p>
Create an account
</p>
</div>
</form>
<!-- END LOGIN FORM -->
<!-- BEGIN FORGOT PASSWORD FORM -->
<form class="forget-form" action="http://keenthemes.com/preview/metronic/theme/admin_2/index.html" method="post">
<h3 class="font-green">Forget Password ?</h3>
<p> Enter your e-mail address below to reset your password. </p>
<div class="form-group">
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" /> </div>
<div class="form-actions">
<button type="button" id="back-btn" class="btn green btn-outline">Back</button>
<button type="submit" class="btn btn-success uppercase pull-right">Submit</button>
</div>
</form>
<!-- END FORGOT PASSWORD FORM -->
<!-- BEGIN REGISTRATION FORM -->
<?php echo form_open('user_signup/login/form-2',['class'=>'register-form','id'=>'register_form']);
?>
<h3 class="font-green">Sign Up</h3>
<p class="hint"> Enter your personal details below: </p>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Roll NO</label>
<?php echo form_input(['name'=>'rollno','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Rollno','value'=>set_value('rollno')]); ?>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Email</label>
<?php echo form_input(['name'=>'email2','type'=>'text','style'=>'text-transform: capitalize;','class'=>'form-control form-control-solid placeholder-no-fix','autocomplete'=>'off','placeholder'=>'Email','value'=>set_value('email2')]); ?>
</div>
<div class="form-actions">
<button type="button" id="register-back-btn" class="btn green btn-outline">Back</button>
<?php echo form_submit('register', 'register',"class='btn btn-success uppercase pull-right'" ); ?>
Note: Check form actions
Here is your updated controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_signup extends CI_Controller {
public function index()
{
$this->load->view('User/signup');
}
public function login()
{
// Checking passed 3rd parameter in URI string.
$submitted_form = $this->uri->segment(3)?$this->uri->segment(3):false;
if ($submitted_form == 'form-1') {
$rules['email1'] = 'required';
$rules['pass'] = 'required';
$this->form_validation->set_rules($rules);
}
if ($submitted_form == 'form-2') {
$rules['rollno'] = 'required';
$rules['email2'] = 'required';
$this->validation->set_rules($rules);
}
if ($this->form_validation->run()) {
if ($submitted_form == 'form-1')
echo 'Form 1 posted !';
else if ($submitted_form == 'form-1')
echo 'Form 2 posted !';
}
$this->load->view('User/signup');
}
}
Let me know if you have any confusion.
Submit by Jquery. For Example in your view
<form id="form1" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="hidden" name="form_type" value="login">
<button type="submit" onClick="login()">Login</button>
</form>
<form id="form2" action="" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<label>Email</label>
<input type="email" name="email">
<input type="hidden" name="form_type" value="register">
<button type="submit" onClick="register()">Login</button>
</form>
Jquery Script
<script>
function login()
{
$('#form1').submit();
}
function register()
{
$('#form2').submit();
}
</script>
Now in your controller
if($_POST)
{
if($_POST['form_type']=='login')
{
// Validate Login
}
elseif($_POST['form_type']=='register')
{
// validate register
}
}

PHP Controller function instantiated before it's called

I'm having a problem with a CRUD application form being displayed on a bootstrap modal.
The issue happens when the form's edit button send the "editId" post var, the modal shows up but the values for the options of the select tag are displayed outside the form.
My controller looks like this:
public function editarUsuarioController(){
if (isset($_GET["editId"])) {
$dataController = $_GET["editId"];
$data = Datos::editUserModel($dataController, "users");
echo'<div id="editModal">
<form method="post" role="form">
<div class="form-group">
<label for="roleEdit">Rol<span></span></label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<select name="roleTypes" class="form-control">
<option selected>
'.$data["rols"].'
</option>
'.$editOptions = MainController::viewRolesController().'
</select>
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn blue" value="Update">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
</div>
</form>
</div>';
} }
As you can see, I'm instantiating another controller from another file which lists the available roles which looks like:
public function viewRolesController(){
$response= Datos::vistaRolesModel("roles");
foreach($response as $row => $item){
echo'<option value="'.$item["id"].'">'.$item["role"].'</option>';
}
}
Any suggestions?
I fixed it by splitting up the echo and using a variable inside the original controller to store the values brought by the vistaRolesModel() model function so this is the new editarUsuarioController() controller function:
public function editarUsuarioController(){
if (isset($_GET["editId"])) {
$dataController = $_GET["editId"];
$data = Datos::editUserModel($dataController, "users");
$roles = Datos::vistaRolesModel("roles");
echo'
<div id="editModal">
<form method="post" role="form">
<div class="form-group">
<label for="roleEdit">Rol<span></span></label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<select name="roleTypes" class="form-control">
<option selected>
'.$data["rols"].'
</option>
';
foreach($roles as $row => $item){
echo'<option value="'.$item["id"].'">'.$item["role"].'</option>';
}
echo'
</select>
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn blue" value="Update">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
</div>
</form>
</div>
';
}
}

Categories