1
I am new in PHP and I came across the following situation:
I have a Modal, which automatically loads the data of a predefined query and is working!
What I need to implement: Enter a variable and display the result in this same Modal. Is this possible? If not, what better way to do?
Below a print of the current screen:
Js
$('#item-add').on('click', function(){
$('body').modalmanager('loading');
setTimeout(function(){
$modal.load('?ng=ps/modal-list/', '', function(){
$modal.modal();
});
}, 1000);
});
Form that calls the Modal
<button type="button" class="btn btn-primary" id="item-add">
<i class="fa fa-search"></i> {$_L['Add Product OR Service']}
</button>
PHP that loads the Modal (Where is my doubt)
case 'modal-list':
//**Consulta padrão atual**
$d = ORM::for_table('sys_items')->order_by_asc('name')->find_many();
//**Consulta com a váriavel (O que eu gostaria de implementar. Neste caso, deixaria de usar a consulta acima)**
//$name = 'caneta';
//$d = ORM::for_table('sys_items')->where_like('name','%'.$name.'%')->find_many();
echo '
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>'.$_L['Products n Services'].'</h3>
</div>
//**Aqui está o input para inserir a variável**
<div class="modal-body">
<div class="input-group">
<div class="input-group-addon">
<span class="fa fa-search"></span>
</div>
<input type="text" name="name" class="form-control" placeholder="'.$_L['Search by Name'].'..."/>
<div class="input-group-btn">
<button class="btn btn-primary">'.$_L['Search'].'</button>
</div>
</div>
//**Resultado abaixo**
<table class="table table-striped" id="items_table">
<thead>
<tr>
<th width="10%">#</th>
<th width="10%">'.$_L['Item Number'].'</th>
<th width="10%">'.$_L['NCM'].'</th>
<th width="40%">'.$_L['Item Name'].'</th>
<th width="10%">'.$_L['Price'].'</th>
</tr>
</thead>
<tbody>
';
foreach($d as $ds){
$price = number_format($ds['sales_price'],2,$config['dec_point'],$config['thousands_sep']);
echo '<tr>
<td><input type="checkbox" class="si"></td>
<td>'.$ds['item_number'].'</td>
<td>'.$ds['ncm'].'</td>
<td>'.$ds['name'].'</td>
<td class="price">'.$price.'</td>
</tr>';
}
echo '
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn">'.$_L['Close'].'</button>
<button class="btn btn-primary update">'.$_L['Select'].'</button>
</div>';
break;
Maybe some of these help: https://answall.com/questions/130803/passar-id-de-um-dado-de-uma-tabela-para-a-modal, https://answall.com/questions/130169/tabela-edit%C3%A1vel-em-php
– Miguel
Hello Miguel. Thanks for your attention. In my case Modal is already initialized and empty table. The idea is to make the query with the variable in Modal itself.
– Marcelo de Oliveira
Hello Marcelo, welcome! I did not understand the question properly said > Enter a variable and display the result in this same Modal. How so? You could explain better?
– Andrei Coelho
The user will enter a keyword in this modal, and you want the result to appear without being redirected. That’s it?
– Andrei Coelho
Hello Andrei. Thank you for the welcome. That’s right. The image above is the modal. When typing the variable and clicking [ Search ] the result is displayed in the table of the same Modal.
– Marcelo de Oliveira
It worked out Marcelo?
– Andrei Coelho
Hi Andrei. I really wanted to thank you for your attention and take your time and knowledge to help me. Unfortunately I still can’t make it work...rs I structured the way you showed, but it didn’t work. I’ll keep trying here. Thank you very much.
– Marcelo de Oliveira
Andrei. It worked! A small adjustment in the urls. Poxa, it was really worth the force. A big hug!
– Marcelo de Oliveira