I'm trying to send data from a form to a PHP page, via AJAX, but I'm not sure if I'm doing it correctly, because I'm not able to echo these variables.
Here is the code of the page containing the form (some information has been hidden, but the code is working):
<body>
<div class="container">
<div class="row">
<div class="mt-5 col-12 col-md-12 col-lg-12">
<form id="adicionar_funcionario" method="POST" enctype="multipart/form-data" class="p-md-5">
<h2 class="text-center"><?php echo $titulo; ?></h2>
<div style="float: left;" class="mt-5">
<img src="../img/avatar.png" alt="Selecione uma imagem" <?php if(isset($errofoto)){echo "class='invalidoimg imgupload'";}else{echo "class='imgupload'";}?> id="imgfoto">
<img src="../img/lixeira.png" id="lixeira" alt="Limpar foto" class="lixeira">
<span class="erro"><?php if(isset($errofoto)){echo $errofoto;}?></span>
</div>
<div class="row mt-5">
<div class="ms-2 ms-lg-5 text-center col-5 col-lg-1 col-md-2 col-sm-2">
<!-- SITUAÇÃO -->
<label for="situacao"> Situação: </label>
</div>
<div class="col-7 col-lg-2 col-md-4 col-sm-4">
<div class="form-check form-switch">
<input id="situacao" name="situacao" class="form-check-input" type="checkbox" value="1" onclick="mudarlabel(this.checked)" <?php if(isset($situacao)){echo "checked";}else{echo "checked";} ?>>
<label class="form-check-label" for="situacao" id="labelsituacao"><?php if(isset($situacao)){echo "Ativado";}else{echo "Ativado";} ?></label>
</div>
</div>
</div>
<div class="ms-lg-5 mt-4 col-12 col-md-12 col-lg-12">
<div class="row">
<div class="ms-lg-5 col-12 col-lg-4 col-md-4 col-sm-4">
<!-- PRONOME -->
<label for="pronome"> Pronome </label>
<select id="pronome" <?php if(isset($erropronome)){echo "class='invalido form-select'";}else{echo "class='form-select'";}?> <?php if (isset($_POST['pronome'])){echo "value='".$_POST['pronome']."'";}?> name="pronome">
<?php
if ((isset($_POST['pronome']))){
?>
<option selected><?php echo $_POST['pronome'];?></option>
<?php
}else{
?>
<option selected>Selecione uma opção</option>
<?php
};
?>
<option value="Ele/Dele">Ele/Dele</option>
<option value="Ela/Dela">Ela/Dela</option>
<option value="Todos">Todos</option>
</select>
<span class="erro"><?php if(isset($erropronome)){echo $erropronome;}?></span>
</div>
<div class="col-12 col-lg-4 col-md-4 col-sm-4">
<!-- NOME COMPLETO -->
<label for="nomecompleto"> Nome completo </label>
<input type="text" id="nomecompleto" placeholder="Como consta no CPF..."<?php if(isset($erronomecompleto)){echo "class='invalido form-control'";}else{echo "class='form-control'";}?> <?php if (isset($_POST['nomecompleto'])){echo "value='".$_POST['nomecompleto']."'";}?> name="nomecompleto">
<span id="erronomecompleto" class="erro"><?php if(isset($erronomecompleto)){echo $erronomecompleto;}?></span>
</div>
</div>
</div>
<div class="ms-lg-5 mt-4 col-12 col-md-12 col-lg-12">
<div class="row">
<div class="ms-lg-5 col-12 col-lg-4 col-md-3 col-sm-4">
<!-- NOME SOCIAL -->
<label for="nomesocial"> Nome social </label>
<input type="text" id="nomesocial" placeholder="Gostaria de ser chamado(a)..." <?php if(isset($erronomesocial)){echo "class='invalido form-control'";}else{echo "class='form-control'";}?> <?php if (isset($_POST['nomesocial'])){echo "value='".$_POST['nomesocial']."'";}?> name="nomesocial">
<span class="erro"><?php if(isset($erronomesocial)){echo $erronomesocial;}?></span>
</div>
<div class="col-12 col-lg-4 col-md-3 col-sm-4">
<!-- NOME -->
<label for="nomeartistico"> Nome Artístico </label>
<input type="text" id="nomeartistico" placeholder="Irá aparecer nos créditos..." <?php if(isset($erronomeartistico)){echo "class='invalido form-control'";}else{echo "class='form-control'";}?> <?php if (isset($_POST['nomeartistico'])){echo "value='".$_POST['nomeartistico']."'";}?> name="nomeartistico">
<span class="erro"><?php if(isset($erronomeartistico)){echo $erronomeartistico;}?></span>
</div>
</div>
</div>
<input accept="image/png,image/jpeg,image/jpg" type="file" id="foto" name="foto">
<input type="text" id="removerfoto" name="removerfoto">
<div class="form-group text-center">
<button id="criar" type="submit" class="mt-5 botao">Criar</button>
</div>
</div>
<!-- Modal -->
<div class="modal hide fade" id="anexar_documentos" tabindex="-1" role="dialog" aria-labelledby="Documentacao" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="TituloModalLongoExemplo">Anexar documentos</h3>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">×</span>
</button>
</div>
<h6 class="ms-3 mt-2"><b><i>Os arquivos precisam ser no formato jpg, png ou pdf e ter, no máximo, 2 MB</i></b></h6>
<div id="anexos" class="modal-body">
Escolha um regime, um cargo e um nível para anexar os documentos
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../bootstrap/_bootstrap/js/enviar_formulario_adicionar_funcionario.js"></script>
</body>
</htlm>
Here is the AJAX code, being called as enviar_formulario_adicionar_funcionario.js:
$(document).ready(function(){
$("#criar").click(function(){
event.preventDefault();
var dados = new FormData(document.getElementById("adicionar_funcionario"));
$.ajax({
url: '../utilities/criarfuncionario.php',
method: 'POST',
dataType: 'json',
cache: false,
contentType: false,
processData: false,
data: {
data: dados
},
success: function(resultado){
alert(resultado.erronomecompleto);
}
})
})
})
And here is the page being sent the data (again some data was removed as it was not relevant to the problem):
<?php
if (((isset($_POST['nomecompleto'])) || (isset($_POST['nomesocial'])) ||
(isset($_POST['nomeartistico'])) || (isset($_POST['telefone'])) ||
(isset($_POST['rg'])) || (isset($_POST['cpf'])) || (isset($_POST['email'])) ||
(isset($_POST['datanasc'])) || (isset($_POST['endereco'])) ||
(isset($_POST['bairro'])) || (isset($_POST['complemento'])) ||
(isset($_POST['cidade'])) || (isset($_POST['cep'])) ||
(isset($_POST['datacontratacao'])) || (isset($_POST['cargo'])) ||
(isset($_POST['projeto'])) || (isset($_POST['datasaida'])) ||
(isset($_POST['regime'])) || (isset($_POST['telefone'])) ||
(isset($_FILES['foto'])) || (isset($_POST['uf'])) ||
(isset($_POST['numero'])) || (isset($_POST['inicio_ferias'])) ||
(isset($_POST['fim_ferias']))) &&
(strpos($_SERVER['REQUEST_URI'], 'cadastro_convite') == false)){
echo json_encode(array ('erronomecompleto' => 'Passei aqui'));
$dados = filter_input_array(INPUT_POST, FILTER_DEFAULT);
$query_campo_obrigatorio = "SELECT * FROM campo_obrigatorio";
$campo_obrigatorio_banco = $conn->prepare($query_campo_obrigatorio);
$campo_obrigatorio_banco->execute();
while($campo_obrigatorio = $campo_obrigatorio_banco->fetch(PDO::FETCH_ASSOC)){
if($campo_obrigatorio['campo_nomecompleto'] == '1'){
if((empty($dados['nomecompleto'])) || (str_replace(" ", "", $dados['nomecompleto']) == "")){
$erronomecompleto = 'Preencha este campo';
}
if(!preg_match("/^[a-zA-Z-' \pL]*$/u", limpapost($dados['nomecompleto']))){
$erronomecompleto = "Apenas letra e espaços em branco neste campo";
}else{
$nomecompleto = limpapost($dados['nomecompleto']);
}
}else{
if((empty($dados['nomecompleto'])) || (str_replace(" ", "", $dados['nomecompleto']) == "")){
$nomecompleto = "";
}
if(!preg_match("/^[a-zA-Z-' \pL]*$/u", limpapost($dados['nomecompleto']))){
$erronomecompleto = "Apenas letra e espaços em branco neste campo";
}else{
$nomecompleto = limpapost($dados['nomecompleto']);
}
}
When I put the echo json_encode inside the IF conditions, I don't get a response, however, if I put it outside the IF conditions, I get the return "Passei aqui".
So I came to the conclusion that my $POST['anything'] is probably not getting anything.
I also tried to pass a value to any field and send the data (to see if it entered the IF conditions), however, I didn't get a return.
I apologize in advance, as I am new to this subject.
Related
I have a food ordering web app in PHP laravel 5.8. The items modal is working fine with the following code but when I am trying to display the deals modal in the same manner, it does not work at all. I am sharing my blade files. The "show.blade.php" file displays the entire front page where these modals have to be shown to the customer. The "modal.blade.php" file is where the modals are defined and their data is coming from the "show.blade.php" page. The first div in the modals file is the one that I want to work and the second is the one that is currently working fine. You can ignore the last modal div.
show.blade.php
#extends('layouts.front', ['class' => ''])
<?php
use Carbon\Carbon;
use App\User;
$name = new User();
?>
#section('content')
#include('restorants.partials.modals')
<section class="section pt-lg-0" id="restaurant-content" style="padding-top: 0px">
<input type="hidden" id="rid" value="{{ $restorant->id }}" />
<div class="container container-restorant">
<hr>
#if ($deals)
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<h1>Deals</h1>
#foreach ($deals as $deal)
<div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
<div class="owl-item">
<div id="addToCart1">
<div class="strip">
<figure style="border-radius: 3rem">
<a onClick="setCurrentDeal({{ $deal->id }})" href="javascript:void(0)"><img
src="{{ $deal->image_url }}_thumbnail.jpg" loading="lazy"
data-src="{{ config('global.restorant_details_image') }}"
class="img-fluid lazy" alt=""></a>
</figure>
<span class="res_title"><b><a onClick="setCurrentDeal({{ $deal->id }})"
href="javascript:void(0)">{{ $deal->name }}</a></b></span><br />
<span class="res_description">{{ $deal->description }}</span><br />
<div class="d-flex justify-content-between">
<div>
#php
$dealItems = [];
$dealItems = App\DealItem::where('deal_id', $deal->id)->get();
#endphp
#foreach ($dealItems as $it)
<h6><strong>{{ $it->item->name }}</strong></h6>
#endforeach
</div>
<h6 class="text-success"><strong>Price:{{ $deal->price }}</strong></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="owl-dots">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
</div>
#endforeach
#endif
</div>
#section('js')
<script>
$(function() {
$('.owl-carousel').owlCarousel({
margin: 50,
autoplay: true,
loop: true
});
});
var deals = [];
var currentDeal = null;
var currentDealSelectedPrice = null;
var lastAdded = null;
var CASHIER_CURRENCY = "<?php echo env('CASHIER_CURRENCY', 'usd'); ?>";
var LOCALE = "<?php echo App::getLocale(); ?>";
/*
* Price formater
* #param {Nummber} price
*/
function formatPrice(price) {
var formatter = new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CASHIER_CURRENCY,
});
var formated = formatter.format(price);
return formated;
}
function setCurrentDeal(id) {
var deal = deals[id];
currentDeal = deal;
$('#modalDealTitle').text(deal.name);
$('#modalDealName').text(deal.name);
$('#modalDealPrice').html(deal.price);
$('#modalDealID').text(deal.id);
$("#modalDealImg").attr("src", deal.image);
$('#modalDealDescription').html(deal.description);
//Normal
currentDealSelectedPrice = deal.priceNotFormated;
// $('#variants-area').hide();
$('.quantity-area').show();
$('#dealModal').modal('show');
}
<?php
$deals =[];
foreach ($deals as $deal){
$theArray = [
'name' => $deal->name,
'id' => $deal->id,
'priceNotFormated' => $deal->price,
'price' => #money($deal->price, env('CASHIER_CURRENCY', 'usd'), true) . '',
'image' => $deal->logom,
'description' => $deal->description,
];
echo 'deals[' . $deal->id . ']=' . json_encode($theArray) . ';';
}
?>
<script>
$(document).ready(function() {
$("#addToCart1").show();
// $('#exrtas-area').show();
$('.quantity-area').show();
});
</script>
#endsection
modals.blade.php
<div class="modal fade" id="dealModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalDealTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalDealImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalDealID" type="hidden"></input>
<span id="modalDealPrice" class="new-price"></span>
<p id="modalDealDescription"></p>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="productModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalID" type="hidden"></input>
<span id="modalPrice" class="new-price"></span>
<p id="modalDescription"></p>
<div id="variants-area">
<label class="form-control-label">{{ __('Select your options') }}</label>
<div id="variants-area-inside">
</div>
</div>
</div>
<div class="col-md-12">
<div id="exrtas-area">
<br />
<label class="form-control-label h4" for="quantity">{{ __('Extras') }}</label>
<div class="row" id="exrtas-area-inside"></div>
</div>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is my view file here i use 5 search field like product, group, branch, startdate and end date. All are placed in different table. Both were worked nicely and searched nicely but now i want some additional option that is when i select a particular branch in group field dynamically show values based on branch field value. Now it is showing whole data in db.
NOTE: i want this change appear when dropdown select.
<div class="row">
<div class="col-md-12">
<div class="tab-content">
<form method="get" id="frmSearchGroupPur" action="<?php echo
base_url('admin/group/listgroup'); ?>">
<div class="form-body">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Product</label>
<div class="col-md-7">
<?php
$product = array();
// if($data['products']){
// foreach ($data['products'] as
$p)
{
// $product[$p['id']] =
$p['name'];
// }
// }
echo form_dropdown('product', $product,
$data['product'], array('class' => 'form-control
select2','id'=>'product'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Branch</label>
<div class="col-md-7">
<?php
$branch = array(NULL=>'Any');
if($data['branches']){
foreach ($data['branches'] as $w){
$branch[$w['id']] = $w['name'];
}
}
echo form_dropdown('branch', $branch,
$data['branch'], array('class' => 'form-control','id'=>'branch_dat'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Group</label>
<div class="col-md-7">
<?php
$group = array(NULL=>'Any');
if($data['groups']){
foreach ($data['groups'] as $g){
$group[$g->id] = $g->name;
}
}
echo form_dropdown('group', $group,
$data['group'], array('class' => 'form-control'));
?>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date From</label>
<div class='input-group date col-md-7'
id='datetimepicker6'>
<?php echo
form_input('fromdate',$data['fromdate'],array('class' => 'form-
control','id'=>'fromdate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date To</label>
<div class='input-group date col-md-7'
id='datetimepicker7'>
<?php echo
form_input('todate',$data['todate'],array('class' => 'form-
control','id'=>'todate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group pull-center">
<button type="submit" id="btnFilter" class="btn
btn-info">Submit</button>
<a href="<?php echo
base_url('admin/group/listgroup'); ?>" class="btn btn-default">Reset</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
and my model file to get group is
function getGroupDetails($groupid=0,$state=''){
$this->db->where('id',$groupid);
$this->db->where('branchid',$state);
$query = $this->db->get('group');
if($query->num_rows()==1){
return $query->row_array();
}else{
return FALSE;
}
and my controller function is
function get_group(){
$state=$this->input->post('brch');
$result = $this->model_group->getGroupDetails($state);
// echo json_decode($result);
}
and my not worked jquery file to change group dynamically is below
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$.ajax({
type:"POST",
url:post_url,
data:function(params)
{
return{ brch : params.brch};
}
});
}
});
I'm trying to get a text from the database but it overflows it's container. I tried putting a lot of lorem ipsum in the original code without the database info and it works fine.
This is what happen when I get the info directly from the database:
And this is a native lorem ipsum in the html file:
This is my html code:
<div class="col-md-8">
<div class="row">
<?php
$query = $mysqli->query("SELECT id,title,preview,author,timepost FROM news ORDER BY timepost DESC LIMIT 3");
$i = 1;
while($array = $query->fetch_array())
{
$date = DateTime::createFromFormat("Y-m-d H:i:s",$array['timepost']); ?>
<div class="col-md-12 mb-3" style="cursor: default;" id="<?php echo 'newsJunebia' . $i; $i++; ?>">
<div class="row">
<div class="col-md-12 bg-negro text-white rounded-top">
<strong><?= $array['title']; ?></strong>
</div>
</div>
<div class="row">
<div class="col-md-8 bg-negro-opacity text-naranja">
<small><em>Publicado el <?=$date->format('d');?> de <?= $date->format('F') ?>o del <?= $date->format('Y'); ?> a las <?= $date->format('H:i') ?></em></small>
</div>
<div class="col-md-4 bg-negro-opacity text-naranja d-flex flex-row-reverse">
<small><em>Autor: <?= $array['author']; ?></em></small>
</div>
</div>
<div class="row">
<div class="col-md-12 bg-negro-opacity text-white">
<p><?php echo $array['preview']; ?></p>
</div>
</div>
<div class="row">
<div class="col-md-12 bg-negro-opacity text-naranja rounded-bottom text-center">
<span style="cursor: pointer;" class="font-weight-bold font-italic text-naranja plusNews">Ver la noticia completa</span>
</div>
</div>
</div>
<?php } ?>
This is the form from where I save this info:
<div class="row">
<div class="col-md-12 mt-4">
<div class="card">
<div class="card-header bg-negro text-white">
<h5 class="card-title text-center">Agregar noticia</h5>
</div>
<form class="form" role="form" method="POST" id="form-news">
<input type="hidden" name="dblanguage" value="es_LA">
<div class="card-body bg-gris text-naranja font-weight-bold">
<div class="form-group">
<label for="newsType">Categoría de la noticia</label>
<select class="custom-select" id="newsType" name="newsType" disabled>
<option>Noticia Junebia</option>
</select>
</div>
<div class="form-group">
<label for="newsTitle">Título de la noticia (<span id="maxCharTitle">60</span> caracteres restantes)</label>
<input type="text" name="newsTitle" id="newsTitle" class="form-control" maxlength="60">
</div>
<div class="form-group">
<label for="newsPreview">Texto de vista previa (<span id="maxChar">120</span> caracteres restantes)</label>
<textarea type="text" name="newsPreview" id="newsPreview" class="form-control" maxlength="100"></textarea>
</div>
<div class="form-group">
<label for="newsContent">Contenido de la noticia</label>
<textarea id="newsContent" name="newsContent" class="form-control"></textarea>
</div>
<input type="hidden" name="username" value="<?= $_SESSION['userName'] ?>">
</div>
<div class="container-fluid justify-content-center d-flex bg-gris">
<button type="submit" class="btn btn-naranja btn-lg mb-2" id="btnAgregar">Agregar</button>
</div>
</form>
</div>
</div>
This is my php file to handle that form:
require_once('../database.php');
if(!isBanned() && isAdmin())
{
if(isset($_POST['newsTitle']))
{
$newsTitle = $_POST['newsTitle'];
$newsPreview = $_POST['newsPreview'];
$newsContent = $_POST['newsContent'];
$newsAuthor = $_POST['username'];
$newsTime = date('Y-m-d H:i:s');
$stmt = $mysqli->prepare("INSERT INTO news(title,preview,content,author,timepost) VALUES(?,?,?,?,?)");
$stmt->bind_param('sssss',$newsTitle,$newsPreview,$newsContent,$newsAuthor,$newsTime);
$stmt->execute();
echo true;
}
else
{
echo false;
}
}
else
{
echo false;
}
I'm using bootstrap 4.1
You just need a space and everything will be fine.
But if your text is looks like as you fetch. You can just try the following css with parent div of text:
word-break: break-all;
I'm using Laravel 4 on this. I have a form with a list of departments in which there are members per department. I used an accordion to place all members under one checkbox of department. Now when I check the checkbox and submit it I want it to be posted on my ajax.
Here's what I can do but found an error.
Syntax error, unrecognized expression: input[name=dept_id:checked
HTML
<div class="col-md-6 col-sm-6">
<div class="blue-steel box portlet">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-calendar"></i>Bulk select Department off day
</div>
</div><!-- /.portlet-title -->
<div class="portlet-body form">
<div class="form-body">
{{Form::open(['url'=>url('admin/schedule'), 'id' => 'department_bulk_off_day', 'class'=>'form-horizontal', 'method'=>'GET'])}}
<div class="form-group">
<label class="col-md-3 control-label" style="padding-left: 0px;">Select Department</label>
<div class="col-md-9">
<!-- <div id="accordion">
<h3><span id="id"><input type="checkbox"/></span>Text More text </h3>
<div>content etc</div>
</div> -->
<div class="employee_checkbox_wrapper" id="accordion">
<?php $department = DB::table('department')->get(); ?>
#foreach($department as $key => $val)
<label><span id="id"><input type="checkbox" name="dept_id[]" value="{{ $val->id }}"/></span>{{ $val->deptName }} </label>
<div>
<?php
$dept_id = $val->id;
$schedule = '';
$desig_ids = DB::table('designation')->where('deptID', $dept_id)->get();
foreach ($desig_ids as $desig_id) {
$emp_des = $desig_id->id;
$employee_desigs = DB::table('employees')->where('designation', $emp_des)->get();
foreach ($employee_desigs as $employee_desig) {
?>
<label style="margin-left: 15px;"><!-- <input type="checkbox" name="employee_id[]" value="{{ $employee_desig->id }}"/> -->
{{ $employee_desig->fullName }}
</label>
<a data-toggle="modal" data-id="{{ $employee_desig->id }}" data-target="#myModal" title="Add this item" class="open-AddBookDialog btn " href="#addBookDialog">
Change Department
</a>
</br>
<?php
}
}
?>
</div>
#endforeach
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" style="margin-top: 20px;">Select Date</label>
<div class="col-md-3">
<div class="input-group input-medium date date-picker" data-date-format="dd-mm-yyyy" data-date-viewmode="years" style="margin-top: 20px;">
<input type="text" class="form-control" name="off_day" value="{{ date('d-m-Y') }}">
<span class="input-group-btn">
<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-md-12 text-center">
{{Form::token()}}
<input type="hidden" name="department_bulk_off_day" value="2">
<button class="btn btn-button button-tip-form-submit">Update</button>
</div><!-- /.col-md-12 text-center -->
</div>
</form><!-- /.form-horizontal -->
</div><!-- /.form-body -->
{{ Form::close() }}
</div><!-- /.portlet-body form -->
</div><!-- /.blue-steel box portlet -->
</div><!-- /.col-md-6 col-sm-6 -->
And here's my JS
<script>
$('#department_bulk_off_day').on('submit', function(e){
e.preventDefault();
var checkValues = jQuery('input[name=dept_id:checked').map(function()
{
return $(this).val();
}).get();
alert(checkValues);
</script>
you can try the following code
var checkValues = jQuery('input[name="dept_id"]').map(function()
{
var this_var = $(this);
if($(this):checked){
return this_var.val();
}
}).get();
Try This. You have the selectors all messed up.
$('#department_bulk_off_day').on('submit', function(e){
e.preventDefault();
var checkValues = $('input[name="dept_id"]:checked').map(function()
{
return $(this).val();
}).get();
alert(checkValues);
I am not able to update multiple columns of the same row with the row matching the userid in codeigniter.
My controller Code is :
exits.php
function update_act_on_resignation(){
global $SITE,$USER;
$data = array();
$data['row'] = new stdClass();
$data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
$data['offices']=$this->mod_common->get_all_offices();
$clients = currentuserclients();
$data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
$data['error_message'] = '';
$data['row']->id = $this->uri->segment(3);
$data['id'] = $this->uri->segment(3);
$data['action'] = 'add';
$data['heading'] = 'Add';
$data['msg_class'] = 'sukses';
$data['path']=$path;
$post_action = $this->input->post('action');
if($post_action=='add' || $post_action =='update' ){
$post_array = $this->input->post();
$action = ($post_action == 'add')?'inserted':'updated';
//echo '<pre>';print_r($SITE);die;
echo $post_array['exit_type'] = 'Employee Initiated';
echo $post_array[$id] = $USER->id;
echo $post_array['custom-105965'];
echo $post_array['manager_comments'];
echo $post_array['accept'];
echo $post_array['agreed_last_date'];
$data['success_message'] = $this->exit_common->update_get_resignation_to_act($post_array,$action);
if($data['success_message'] == 'Record '.$action.' successfully'){
$data['row'] = new stdClass();
$data['row']->id = $this->uri->segment(3);
$data['row']->status = 1;
}
}
$this->data['maincontent'] = $this->load->view('maincontents/view_resignation_action', $data,true);
echo "Resignation withdrawn successfully!";
$this->load->view('layout', $this->data);
}
I am echoing the results got from a form to check if i am receiving the sent form elements and i have received everything properly. i.e i am recieving 67 for $post_array[$id] Yes for $post_array['custom-105965'] asd for $post_array['manager_comments'] Accept for $post_array['accept'] and 01-01-1970 as $post_array['agreed_last_date'] after the echo.
My Model code is:
exit_common.php
function update_get_resignation_to_act($post_array,$action){
$this->load->database();
$this->db->where('userids', $post_array['id']);
$dbdata['discussion'] = $post_array['custom-105965'];
$dbdata['manager_comments'] = $post_array['manager_comments'];
$dbdata['last_status'] = $post_array['accept'];
$dbdata['agreed_date'] = $post_array['agreed_last_date'];
$this->db->update('pr_resignation_requests', $dbdata);
return;
}
I think something is wrong with the model update function. But not able to figure out what is wrong as a similar function is working for updating a single column in db. Am i missing something? Its a mysql db.
My View Code is:
view_resignation_action.php
<style>
label{font-weight:bold;}
.hbox .col {
display: table-cell;
float: none;
height: 100%;
vertical-align: top;
width:100%;
}
</style>
<div class="new">
<section class="content-header">
<h1>
Resignation Action
</h1>
<ol class="breadcrumb" >
<li><i class="fa fa-home"></i> Home</li>
<li>People Connect</li>
<li>Exit Tracker</li>
<li class="active">Exit Details</li>
</ol>
</section>
<input type="hidden" id="page_name" value="requests">
<div class="container-fluid">
<div class="row">
<!-- Thought Day-->
<div class="panel wrapper clearfix m-b-none">
<!-- Horizontal Form -->
<div class="box-header with-border">
</div><!-- /.box-header -->
<!-- form start -->
<?php if($error_message!=''){?>
<div class="row-fluid return-message success-message <?php echo $msg_class; ?>"><?php echo $error_message;?></div>
<?php } else { ?>
<?php echo form_open('exits/update_act_on_resignation/',array('name'=>'addostcstevent','id'=>'addostcstevent','method'=>'post','autocomplete'=>'on','class'=>'form-horizontal'))?>
<?php echo form_hidden(array('id'=>$USER->id,'action'=>$action));?>
<?php foreach($rows as $row){ ?>
<div class="panel-body">
<div class="control-group form-group">
<div class="col-md-6">
<div class="controls">
<div class="col-md-5">
<label class="control-label" style="text-align:left">Name of the employee </label>
<div class="controls"><?php echo $row->firstname; ?>
</div>
</div>
<div class="col-md-5">
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label" style="text-align:left">Date of request </label><div class="controls">
<?php echo $row->resignations_date; ?>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="control-group form-group">
<div class="col-md-6 ">
<label class="control-label" style="text-align:left">Requested Last Working Date</label>
<div class="controls">
<div class="col-md-10">
<?php echo $row->requested_date; ?>
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label">Reason</label>
<div class="controls">
<div class="col-md-9">
<?php echo $row->exit_type; ?>
</div>
</div>
</div>
<div class="col-md-6 pull-right">
<label class="control-label">Comments from Employee</label>
<div class="controls">
<div class="col-md-9">
<?php echo $row->comments; ?>
</div>
</div>
</div>
<br><br><br><br><br><br><br>
<fieldset id="f1" class="col-md-6 pull-left"> <!-- start fieldset -->
<div class="label">
</label>
</div>
<div class="input">
</div>
</div>
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" style="text-align:left">
<label class="control-label" style="text-align:left">Have you had a discussion with Employee?</label>
<table>
<td valign="top">
<input id="custom-105965_0" class="custom-105965" name="custom-105965" value="Yes" type="radio">
<label for="custom-105965_0">Yes
<br>
</label>
</td>
<td valign="top">
<input id="custom-105965_1" class="custom-105965" name="custom-105965" value="No" type="radio">
<label for="custom-105965_1">No
</label>
</td>
</table>
<td valign="top">
<div class="fieldset" id="bsd-field-custom-105967-group">
<div class="col-md-6 pull-left">
<label class="control-label">Please enter your comments</label>
<div class="controls">
<div class="col-md-12">
<textarea required class="form-control" name="manager_comments"></textarea>
<!--<input placeholder="Please enter your comments" class="" id="dateofrequest" type="text" name="todays_date" value=""/> <br><br>-->
</div>
</div>
<label class="control-label">Action</label>
<div class="controls">
<div class="col-md-9">
<?php $dd_list = array(
'Accept' => 'Accepted',
'Reject' => 'Rejected',
);
echo form_dropdown('accept', $dd_list, 'Accept');
?>
</div>
</div>
<label class="control-label">Agreed Last Working day</label>
<div class="controls">
<div class="col-md-9">
<input placeholder="Agreed Last Working day" class=" m-wrap col-md-8 form-control " id="startdt" type="text" name="agreed_last_date" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</div>
</div>
<br><br>
<div class="col-md-9">
</div>
</div>
</div>
<!-- If its a no -->
<div class="fieldset" id="bsd-field-custom-105867-group">
<div class="col-md-6 pull-left">
<div class="alert alert-success alert-dismissable">
<label type="button"></label>
Please have a discussion with the employee.
</div>
</div>
</div>
</td>
</table>
</td>
</tr>
</fieldset><!-- End Fiedset -->
</div>
</div>
<?php }?>
<div class="clearfix"></div>
<div class=" box-footer">
<button type="submit" class="btn btn-info pull-right" style="margin:0px 10px">submit</button>
</div>
</form>
<?php } ?>
<div class="clearfix"></div>
</div>
</div>
</div>
</section>
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-fileupload/bootstrap-fileupload.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.js"></script>
<script>
$(".fieldset").hide();
$(document).ready(function () {
$("[id^=bsd-field-custom-1059]").hide();
$(".custom-105965").change(function () {
$("[id^=bsd-field-custom-1059]").toggle(this.value == 'Yes');
});
});
$(document).ready(function () {
$("[id^=bsd-field-custom-1059]").hide();
$(".custom-105965").change(function () {
$("[id^=bsd-field-custom-1058]").toggle(this.value == 'No');
$('.alert').show()
});
});
$(document).ready(function(){
$("#startdt").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: "-90:+0",
endDate: new Date(),
autoclose: true
}).on('changeDate', function (selected) {
var minDate = new Date(selected.date.valueOf());
$('#enddt').datepicker('setStartDate', minDate);
});
$("#enddt").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: "-90:+0",
endDate: new Date()
});
$(".date-picker").datepicker();
$('.timepicker-default').timepicker();
$('#report_date').datepicker( {
format: "mm-yyyy",
viewMode: "months",
minViewMode: "months"
});
$(".select2").select2({
placeholder: "Select an option",
allowClear: true
});
$("#asset_type").change(function(){
if($(this).val() == '-1') {
$("#new_type").show();
}
else
{
$("#new_type").hide();
}
});
$("#manufacturer").change(function(){
if($(this).val() == '-1') {
$("#new_manufacturer").show();
}
else
{
$("#new_manufacturer").hide();
}
});
$("#supplier").change(function(){
if($(this).val() == '-1') {
$("#new_supplier").show();
}
else
{
$("#new_supplier").hide();
}
});
});
</script>
Mysql Table is :
Try Below Snippet
function update_get_resignation_to_act($post_array,$action)
{
$this->load->database();
$this->db->where('userids', $post_array['id']);
$dbdata = array(
"discussion" => $post_array['custom-105965'],
"manager_comments" => $post_array['manager_comments'],
"last_status" => $post_array['accept'],
"agreed_date" => $post_array['agreed_last_date']
);
$this->db->update('pr_resignation_requests', $dbdata);
/**
* if required add this code here to check
*
* echo $this->db->last_query();
*/
return;
}