I have a concern for recovering value contained in a form (pop-up) in a field of another form (php), the collect value in the field must be in the form of a character string array. when I test my page, the result I got in my field is an array of (undefined: undefined: undefined: ..........) Here is my code:
in PHP:
<div class="form-group col-md-3">
<label>Quantité & Taille*:</label>
<button type="button" class="btn btn-default form-control" data-target="#tailleModal" onclick="jQuery('#tailleModal').modal('toggle');return false;">Quantité & Taille</button>
</div>
<!-- Modal -->
<div class="modal fade" id="tailleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Quantité & Taille</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container-fluid">
<?php for($i=1; $i<=12; $i++): ?>
<div class="form-group col-md-4">
<label for="taille <?php echo $i ;?>">Taille:</label>
<input type="text" name="taille <?php echo $i ;?>" id="taille <?php echo $i ;?>" class="form-control">
</div>
<div class="form-group col-md-2">
<label for="taille <?php echo $i ;?>">Quantité:</label>
<input type="number" name="quantite <?php echo $i ;?>" value="" min="0" id="quantite <?php echo $i ;?>" class="form-control">
</div>
<?php endfor; ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="updatetaille();jQuery('#tailleModal').modal('toggle');return false;">Enregistrer Modification</button>
</div>
</div>
</div>
</div>
<div class="form-group col-md-3">
<label for="tailles">Quantité & Taille précédent:</label>
<input type="text" class="form-control" name="tailles" id="tailles" value="<?php echo ((isset($_POST['tailles']))? $_POST['tailles']:'') ;?>" readonly>
</div>
With Ajax
function updatetaille(){
var i,taillecaract='';
var taille=$('#taille'+i).val();
var quantite=$('#quantite'+i).val();
for(var i=1;i<=12;i++){
if (taille!='') {
taillecaract+=taille+':'+quantite+',';
}
}
$('#tailles').val(taillecaract);
}
Thanks for your help.
When I do what you do, the undefined error: undefined is displayed. I show you the result using imageimg of test when I press "Enregistrer Modification"the result displays undefined: undefined ...img of test
thanks for your help.
In your php, where you set ids, like this
id="quantite <?php echo $i ;?>"
remove the space, like this
id="quantite<?php echo $i ;?>"
That should help, because in your javascript you have jquery using selectors like this
var taille=$('#taille'+i).val();
var quantite=$('#quantite'+i).val();
with no space
Related
i have tried to create form input fields dynamically and i succeeded but when all other fields are being submitted, only the dynamically created fields are not please help out.. thanks..
my javascript is working fine, its creating the fileds just fine inside the modal..
the problem is when i am submitting it only the dynamically added fields are not submitted..
<form action='<?php echo $_SERVER['PHP_SELF'];?>' method="post">
<div class="col-md-6">
<div class="form-group">
<h6> Contact person in case of emergency</h6
<input class="form-control" placeholder="Contact person" required="" pattern="([A-Z][a-z]*\s*[A-Z]*[a-z]*\s*[0-9]*)" title="Alphbetical characters only, capitalize first letter, full name then phone number" value="<?php echo $info[0]['contactperson'];?>" name="contactperson" type="text">
</div>
</div>
<input class="form-control" hidden placeholder="familymembers" id="fm" value="<?php echo $info[0]['familymembers'];?>" name="familymembers" type="number">
<div class="col-md-6">
<div class="form-group">
<h6> </h6>
<button class="btn btn-success">Edit Family Members List</button>
</div>
</div>
//this is a script to add new input fields daynamically
<script type="text/javascript">
function getfmembers(){
var fn=document.getElementById('fm').value;
for (var i = 0; i < 1; i++) {
document.getElementById('fm').value++;
k=document.getElementById('fm').value;
var btn='<div class="form-group"><input class="form-control" name="fmlis" placeholder="Name of the family member" id="'+k+'" type="text"></div>';
$("#after").after(btn);
alert(document.getElementById(k).name);
}
}
function removefmembers(){
var fn=document.getElementById('fm').value;
$("input").remove("#"+fn);
document.getElementById('fm').value--;
}
</script>
// this is the modal to submit the inputs and its inside the form tag
<div class="modal fade" id="seefmlist" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Family Members List</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-3">
<span onclick="getfmembers()" class="btn btn-sm btn-success">Add Member</span>
</div>
<div class="col-md-3">
<span onclick="removefmembers()" class="btn btn-sm btn-danger">Delete Last Member</span>
</div>
</div>
<br>
<div id="after">
<?php
$flist=explode(",",$info[0]['familylist']);
if (count($flist)>1) {
for ($qq=0; $qq < count($flist)-1 ; $qq++) {
echo '<div class="form-group"><input class="form-control" id="'.($qq+1).'" value="'.$flist[$qq+1].'" name="fmlist'.($qq+1).'" type="text"></div>';
}
}
?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Update changes</button>
</div>
</div>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" name='submitupdate' class="btn btn-primary mt-4">Update Employee information</button>
</div>
</form>
line 31 :
for (var i = 0; i < 1; i++) {
only runs once, if you wanted to have this add more than one you will need to fix
also probably the problem you are hung up on
line 34 : name="fmlis" later in your code you have name="fmlist'.($qq+1).' so, on line 34 you probably want to concat k+1 to the name...
I have two modal in one page. One is for edit and the other is for create. In both modal contain select2 option. And the option I get from my database. I want to use the data for both of modal. But I get error in modal create and no error for modal edit. In modal create, it can't display the data in select option. Can anyone help me?
I try this
public function detail_produk(){
$data['item']=$this->admin_model->get_all_detail_produk();
$data['ukuran'] = $this->admin_model->get_ukuran();
$data['sidebar'] = $this->load->view('sidebar','',TRUE);
$data['header'] = $this->load->view('header','',TRUE);
$this->load->view('detail_produk', $data);
}
The View
<div class="modal fade" role="dialog" id="detail_user">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Ukuran</label>
<div class="col-sm-10">
<select class="form-control select2" style="width: 100%;" id="ukuran">
<option selected="true" disabled="disabled">Pilih Ukuran</option>
<?php foreach ($ukuran as $ukuran) { ?>
<option value="<?php echo $ukuran['id'];?>"><?php echo $ukuran['size'];?></option>
<?php } ?>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="button-simpan" class="btn btn-primary mr-auto" >Simpan</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Kembali</button>
</div>
</div>
</div>
</div>
<div class="modal fade" role="dialog" id="tambah">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form id="form1">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Ukuran</label>
<div class="col-sm-10">
<select class="form-control select2" style="width: 100%;" id="ukuran_id">
<option selected="true" disabled="disabled">Pilih Ukuran</option>
<?php foreach ($ukuran as $ukuran) { ?>
<option value="<?php echo $ukuran['id'];?>"><?php echo $ukuran['size'];?></option>
<?php } ?>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="button-tambah" class="btn btn-primary mr-auto" >Tambah</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Kembali</button>
</div>
</div>
Thank You :)
foreach ($ukuran as $ukuran)
You can not use same variable. Do something like follows
foreach ($ukuran as $value){
//now you can
echo $value['id'];
}
Without Modal, user_timeout.php does not have a problem but When I use modal, as you can see at the picture below the problem is. But they have same logic codes so I dont know what the problem is. I want to use modal for some quality design so help me guys thank you
logs.php
<a rel="tooltip" title="Timeout" id="<?php echo $idlogs; ?>" href="user_timeout.php<?php echo '?id='.$idlogs; ?>" class="btn btn-info"><i class="icon-minus icon-large"></i> Manual Time-Out</a>
And for Modal
<a rel="tooltip" title="timeout" id="<?php echo $idlogs; ?>" href="#timeout<?php echo $idlogs; ?>" data-toggle="modal" class="btn btn-success"><i class="icon-pencil icon-large"></i> Manual Time-Out</a>
<?php include('modal_time_user.php'); ?>
user_timeout.php
<?php $get_id= $_GET['id']; ?>
<div class="container">
<div class="margin-top">
<div class="row">
<div class="span12">
<?php
$query=mysqli_query($dbcon,"select * from user_logs_tbl where id ='$get_id'")or die(mysqli_error());
$row=mysqli_fetch_assoc($query);
$iduser=$row['user_id'];
$idlogs=$row['id'];
?>
<div class="alert alert-info"><i class="icon-pencil></i> Manual Time-out</div>
<p><a class="btn btn-info" href="logs.php"><i class="icon-arrow-left icon-large"></i> Back</a></p>
<div class="addstudent">
<div class="details">Please Enter Details Below</div>
<form class="form-horizontal" method="POST" enctype="multipart/form-data">
<div class="control-group">
<br>
<div class="control-group">
<label class="control-label" style="margin-left:10%;" for="inputEmail">Time-Out:</label>
<div class="controls">
<input type="time" id="inputEmail" name="timeout" placeholder="Time">
</div>
</div>
<br>
<div class="control-group">
<div class="controls">
<button name="timeouts" type="submit" style="margin-left:16%;" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if (isset($_POST['timeouts'])){
$timeout=$_POST['timeout'];
$timeout = date('Y-m-d H:i:s', strtotime(str_replace('-', '/',
$timeout)));
mysqli_query($dbcon,"UPDATE user_logs_tbl set time_out = '$timeout' where id='$idlogs'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
But If I change it into modal form, it's working but all data will change if I change one
modal_time_user.php
<div id="timeout<?php echo $idlogs; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<div class="alert alert-info"><strong>Time</strong></div>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" for="inputEmail">Time-Out :</label>
<div class="controls">
<input type="time" id="inputEmail" name="time_out" pattern="[a-zA-Z0-9]{5,}" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="enter" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
</div>
</div>
<?php
if (isset($_POST['enter'])){
$timeout=$_POST['time_out'];
$timeout = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $timeout)));
mysqli_query($dbcon,"UPDATE user_logs_tbl SET time_out='$timeout' where id = '$idlogs'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
Problem
After Inserting a Time Out In USER ID 45
Why is this not working, because of a problem in Bootstrap or ajax?
This is my modal update:
<div class="container">
<!-- Modal update -->
<div class="modal fade" id="myModals<?php echo $row->id ;?>" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Data</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="user">Username:</label>
<input type="user" class="form-control" id="users<?php echo $row->id ;?>" value="<?php echo $row->username ;?>">
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" id="passwords<?php echo $row->id ;?>" value="<?php echo $row->password ;?>">
</div>
<button onclick='update("<?= $row->id ?>")' type="submit" class="btn btn-default">Update</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
And this is my ajax:
function update(id){
var users = $("#users"+id).val();
var passwords = $("#passwords"+id).val();
$.ajax({
dataType:'html',
url:"update.php",
type:"POST",
data:"users="+users+"&passwords="+passwords+"&id="+id,
}).done(function(data){
load();
$('back-drop').remove();
});
}
Why is this not working when I submit the change, the modal form is not closed completely like this:
Please recheck your selector in the hide() syntax. You've forgotten the # in front.
Change this:
$('myModals'+id).modal('hide');
To this:
$('#myModals'+id).modal('hide');
For checking such issues, you should use Google Chrome and press CTRL + Shift + J. The possible syntax errors will be shown in the console.
I am using Twitter Bootstrap for both tabs and modals. I have two tabs that use identical code. In the first tab the modals work perfectly, but in the second tab the screen will darken but the modal does not appear.
here is my code for calling the modal (same code used in both tabs) in list.php:
<a type="button" href="edit.php?id='.$id.'" data-target="#edit_modal" data-toggle="modal">Edit</a>
here is my modal in list.php
<div class="modal hide fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Edit Testimonials</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
</div>
and here is edit.php where the true body of the modal is
<div id="edit_modal">
<div class="modal-body">
<?php echo ($name_error != "") ? $name_error : ""; ?>
<form class="form-horizontal" action="edit.php?id=<?php echo $id; ?>" method="post">
<div class="control-group">
<label class="control-label">Testimonial</label>
<div class="controls">
<textarea class="input-xlarge" name="body" cols=100 rows=5><?php echo $testimonial['body']?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Author</label>
<div class="controls">
<textarea class="input-xlarge" name="author" cols=100 rows=5><?php echo $testimonial['author']?></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Update Testimonial" name="submit-form" />
Close
</div>
</form>
</div>