how to looping a card? (with all element in the card) - php

I want to ask some question about looping a card.. (https://ibb.co/WpxghNg) when I loop the card, the card can loop while the elements in it can't. all elements don't work, can't switch on / off.
when I loop the card, the card can loop while the elements in it can't. all elements don't work, can't switch on / off.
this is sql farm_node (https://ibb.co/S304TyQ)
elseif($_POST['p']=="show_node"){
$sn=$_POST['sn'];
$q=mysqli_query($link, "SELECT node from farm_node WHERE SN=\"$sn\"");
while($d = mysqli_fetch_row($q)){
$node[]=$d[0];
}
$daftar=array('node'=>$node);
echo json_encode($daftar);
}
$("#newval").change(function() {
sn = $("option:selected").attr('sn');
namafarm = $("option:selected").val();
isi = $("#show_siram2");
if (namafarm == "1") {
console.log("value 1")
console.log(sn)
$("#bungkus_siram").empty();
$("#show_hidro").show();
} else {
console.log("value 2")
console.log(sn)
$("#show_hidro").hide();
$("#bungkus_siram").empty();
$.ajax({
method: "POST",
url: "../inc/olah.php",
data: {
p: "show_node",
'sn': sn,
},
dataType: "json"
})
.done(function(d) {
var html = '<div class="card mx-auto" style="width:350px" >';
html += '<div class="card-body">';
html += '<form id="form_node" >';
html += '<div class="custom-control custom-switch" style="margin-left:60px;">';
html += '<input type="checkbox" class="custom-control-input" id="pompa">';
html += '<label class="custom-control-label" for="pompa">Pompa</label>';
html += '</div>';
html += '</form>';
html += '<h5 class="card-title"></h5>';
html += '<button type="submit" name="nama"class="data-farm btn btn-success btn-sm" id="farm">Set Node</button>';
html += '</div>';
html += '</div>';
jml = d.node.length;
var isi = $("#form");
var node = d.node;
for (var i = 0; i < jml; i++)
//$("#form").show();
{
isi = $("#show_siram2");
$("#field").append(html);
$('#field #field .custom-control .custom-switch:eq(' + i + ')').val(node[i]);
$('#field .card-title:eq(' + i + ')').append(node[i]);
$("#field .data-farm:eq(" + i + ")").val(node[i]);
console.log(node[i]);
}
})
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group ">
<label for="serial-number">Serial Number:</label>
<select class="serial-number form-control" name="serial-number" class="custom-select mb-3" id="newval">
<option>Serial Number</option>
<?php
$q=mysqli_query($link,"SELECT produk.SN, produk.nama, produk.produk FROM produk LEFT JOIN farm ON produk.SN=farm.SN WHERE username=\"$_SESSION[username]\"");
while($d=mysqli_fetch_row($q)) {
echo "<option value=$d[2] sn=$d[0]>$d[1]</option>";
}
?>
</select>
</div>
<div class="form-group" id="field">
<div class="row" id="bungkus_siram" style="display:block">
<div class="card" id="show_siram1">
<div class="card-body">
<h5 class="card-title">Node X</h5>
<form id="form_node">
<div class="custom-control custom-switch" style="margin-left:80px;">
<input type="checkbox" class="custom-control-input" id="pompa">
<label class="custom-control-label" for="pompa">Pompa</label>
</div>
<label for="k_max">Kelembapan Maksimum</label>
<input type="range" class="custom-range" id="k_max" name="k_max">
<label for="k_min">Kelembapan Minimum</label>
<input type="range" class="custom-range" id="k_min" name="k_min">
<button type="submit" name="nama" class="data-farm btn btn-success btn-sm" id="farm">Set Node</button>
</div>
<div class="form-group">
<button type="submit" id="save_addPlant" class="btn btn-primary btn-success">Save</button>
<button type="button" class="btn btn-outline-danger pull-left" data-dismiss="modal">Close</button>
</div>
</form>
</div>
<div class="card" id="show_siram2">
<div class="card-body">
<h5 class="card-title">Node X</h5>
<form id="form_node">
<div class="custom-control custom-switch" style="margin-left:60px;">
<input type="checkbox" class="custom-control-input" id="pompa">
<label class="custom-control-label" for="pompa">Pompa</label>
</div>
<label for="k_max">Kelembapan Maksimum</label>
<input type="range" class="custom-range" id="k_max" name="k_max">
<label for="k_min">Kelembapan Minimum</label>
<input type="range" class="custom-range" id="k_min" name="k_min">
<button type="submit" name="nama" class="data-farm btn btn-success btn-sm" id="farm">Set Node</button>
</div>
<div class="form-group">
<button type="submit" id="save_addPlant" class="btn btn-primary btn-success">Save</button>
<button type="button" class="btn btn-outline-danger pull-left" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
I want the looping card and its contents as much as possible.

What do you mean by --- the card can loop while the elements in it can't. all elements don't work, can't switch on / off.
Do you mean nothings showing up anything on the browser?
because I noticed that, on your parent div. it has style like this
<div class="row" id="bungkus_siram" style="display:none">
maybe you change the style to- display:block
to show?
Im guessing.

Related

How can I have if/else condition inside a large php string variable?

I have a large php string variable. I want to put php if/else condition inside it, so the edit and delete buttons to be displayed only to the author of the comment and not to everyone, but my code is not working. I used a colon to define the if/else condition, but it doesn’t work. Regular if/else condition also doesn’t work.
Here is my php code:
$user_id = $_SESSION['user_id'];
$if = "if ($user_id == $row['user_id']): ";
$else = "else: ";
$endif = "endif; ";
foreach($result as $row)
{
$output .= '
<div class="panel panel-default">
<div class="panel-body">'.$row["comment"].'</div>
<div class="panel-footer">
'. $if .'
<form class="input-group form-row" action="comment_delete1.php" method="post" enctype = "multipart/form-data">
<div class="input-group-prepend">
<input type="hidden" name="comment_id" id="comment_id" value="'.$row["comment_id"].'" />
<input type="hidden" name="user_id" id="user_id" value="'.$row["user_id"].'" />
<input type="submit" name="submit" id="submit" class="submit btn btn-default" value="Delete" />
</div>
</form>
<button type="button" class="btn btn-default edit" id="'.$row["comment_id"].'" >Edit</button>
'. $else .'
<button type="button" class="btn btn-default reply" id="'.$row["comment_id"].'" >Reply</button>
'. $endif .'
</div>
</div>
';
}
echo $output;
In order to do this correctly the condition must be evaluated:
foreach($result as $row)
{
$output .= '
<div class="panel panel-default">
<div class="panel-body">'.$row["comment"].'</div>
<div class="panel-footer">';
if ($user_id == $row['user_id']) {
$output .= '<form class="input-group form-row" action="comment_delete1.php" method="post" enctype = "multipart/form-data">
<div class="input-group-prepend">
<input type="hidden" name="comment_id" id="comment_id" value="'.$row["comment_id"].'" />
<input type="hidden" name="user_id" id="user_id" value="'.$row["user_id"].'" />
<input type="submit" name="submit" id="submit" class="submit btn btn-default" value="Delete" />
</div>
</form>
<button type="button" class="btn btn-default edit" id="'.$row["comment_id"].'" >Edit</button>';
} else {
$output .= '<button type="button" class="btn btn-default reply" id="'.$row["comment_id"].'" >Reply</button>
</div>
</div>
';
}
}
echo $output;
This is really not a good way to do this and you should consider refactoring your code to make this much neater and easier to read.
Here is the solution:
If we put conditions inside php string or heredoc, php will treat them as string and will display them on the screen as string. So we cannot have conditions inside string.
I put the if else conditions outside the php string variable, and I created two php string variables, one with delete and edit buttons, and the other one without delete and edit buttons. So if the user_id is equal to session user id, the php string variable with delete and edit buttons will be displayed. And, else if the user_id is not equal to session user id, the php string variable without delete and edit buttons will be displayed. The php string variable will be echoed at the end of all conditions.
Here is the php code:
$user_id = $_SESSION['user_id'];
foreach($result as $row) {
if ($row['user_id'] === $user_id) {
$output .= '
<div class="panel panel-default">
<div class="panel-body">'.$row["comment"].'</div>
<div class="panel-footer">
<form class="input-group form-row" action="comment_delete1.php" method="post" enctype = "multipart/form-data">
<div class="input-group-prepend">
<input type="hidden" name="comment_id" id="comment_id" value="'.$row["comment_id"].'" />
<input type="hidden" name="user_id" id="user_id" value="'.$row["user_id"].'" />
<input type="submit" name="submit" id="submit" class="submit btn btn-default" value="Delete" />
</div>
</form>
<button type="button" class="btn btn-default edit" id="'.$row["comment_id"].'" >Edit</button>
<button type="button" class="btn btn-default reply" id="'.$row["comment_id"].'" >Reply</button>
</div>
</div>
';
} else if ($row['user_id'] !== $user_id) {
$output .= '
<div class="panel panel-default">
<div class="panel-body">'.$row["comment"].'</div>
<div class="panel-footer">
<button type="button" class="btn btn-default reply" id="'.$row["comment_id"].'" >Reply</button>
</div>
</div>
';
}
}
echo $output;

Dropzone sending all queue of uploaded files to the controller once

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'];
}}

how to save previous page clikable url in database using php?

i have following div in project. after clicking on "request for demo" button , it will redirect to next window to registration form (link is mentioned in javascript function). i want to save relevant div id in database after clicking on button and save register.
following is my html and javascript
<div class="row">
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Supermarkets, Fruits & Vegetables</b></span>
<hr>
<p>Uninterrupted fast billing, inventory control, CRM & Loyalty programs makes your shoppers happier</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<!--<button type="button" onclick="openWin()" class="btn btn-default" id="demo-btn" data-toggle="modal" data-target="#demoModal">Request for Demo</button>-->
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Supermarkets, Fruits and Vegetables" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Grocery & Departmental Stores</b></span>
<hr>
<p>POS for grocery, departmental store, hypermarket and convenience store with GSmartPOS</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Grocery and Departmental Stores" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Pharmacy, Medical Shop POS</b></span>
<hr>
<p>Prefilled drug index, update stock position and bill from Day One. Manage batches and expiry with ease</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Pharmacy Medical Shop POS" >Request for Demo</button>
</div>
<br>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Apparel & Footwear</b></span>
<hr>
<p>POS Features like matrix-inventory, non-moving stock analysis, can help keep inventory latest and fashionable</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Apparel and Footwear" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Electrical & Electronics POS</b></span>
<hr>
<p>Perfect solution to manage serialized inventory for mobile, computer electrical and electronics shops</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Electrical and Electronics POS" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Fashion Jewellery Shop</b></span>
<hr>
<p>An integrated, modular & scalable POS for furniture, glass & crockeries, opticals, music, toys & baby shop retail</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Fashion Jewellery Shop" >Request for Demo</button>
</div>
</div>
following function is called on each div button,
<script>
function openWin() {
window.open("register.php");
}
</script>
after clicking on each div button following form will be open in new window,
<div class="register">
<div class="container">
<div class="row main">
<div class="main-register main-center">
<form class="" method="post" id="contact-form">
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="name" placeholder="Enter your Name"/>
</div>
</div>
</div>
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="email" placeholder="Enter your Email"/>
</div>
</div>
</div>
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="contact_no" placeholder="Enter your contact number"/>
</div>
</div>
</div>
<input type="hidden" id="requestType">
<div class="form-group ">
<button class="btn btn-primary btn-lg btn-block register-button submit">Register</a>
</div>
</form>
<span class="success" style="display:none">Thank You for Register with us.</span>
</div>
</div>
</div>
</div>
form will be save using ajax and php
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" >
$(function() {
$(".modalBtn").click(function(){
var formName = $(this).attr("id");
$('#requestType').val(formName);
$('.success').hide();
$('.error').hide();
$('#contact-form').show();
$("#demoModal").modal();
});
$(".submit").click(function() {
var name = $("#name").val();
var requestType = $('#requestType').val();
var contact_no = $("#contact_no").val();
var email = $("#email").val();
//alert(requestType);
var dataString = 'name='+ name + '&contact_no=' + contact_no + '&email=' + email+ '&requestType=' + requestType;
if(name=='' || contact_no=='' || email=='')
{
$('.success').fadeOut(200).hide();
$('.error').show();
}
else
{
$.ajax({
type: "POST",
url: "register.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
$('#contact-form').hide();
}
});
}
return false;
});
});
</script>
Php code to insert data is,
<?php
require('connection.php');
if($_POST) {
$id = $_POST['regid'];
$name = $_POST['name'];
$contact_no = $_POST['contact_no'];
$email = $_POST['email'];
$requestType = $_POST['requestType'];
if ($id == '') {
$sql = "INSERT INTO registration(name,contact_no,email,requestType) VALUES ".
"('".$name."', '".$contact_no."', '".$email."','".$requestType."')";
}
$query_result = mysql_query( $sql );
if(!$query_result ) {
echo 'Could not enter data: ' . mysql_error();
} else {
//header("Location: lead-view.php?s=Y");
$successMsg = 'Record instered successfully';
}
}
?>
i want save those div id as in url after submitting form of relevant dive click button. url will be save in "requestType" field in database. please help.
You can make use of sessionStorage for passing the requestType value.
https://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/
While calling openWin() pass the div value to it. For example:
<button type="button" onclick="openWin('abc')" class="modalBtn btn btn-default" id="Supermarkets, Fruits and Vegetables" >Request for Demo</button>
Then save this value in sessionStorage as follows:
function openWin(div_value) {
sessionStorage.setItem("registerType", div_value);
window.open("register.php");
}
You can retrieve this variable in register.php:
var registerType = sessionStorage.getItem("registerType");
Add this value to the hidden input control in register form and save it to database.
<input type="hidden" id="requestType">

Submit INPUT to the database to return as a Table PHP jQuery MySQL

I'm trying to refresh a data input into an INPUT through a form and then SUBMIT this to the database to return it as a table on the same page. I want it to do this without showing the refresh of the page.
This is what I have currently. When I put data into any of the INPUT fields and click SUBMIT nothing happens and nothing shows for an error.
<?php
session_start();
error_reporting (E_ALL);
require '../core/cnn.php';
if(isset($_POST['submitsearchprojno'])) {
$searchprojno = $_POST["searchprojno"];
}
if(isset($_POST['submitsearchadd'])) {
$searchaddress = $_POST["searchaddress"];
}
if(isset($_POST['submitsearchpc'])) {
$searchpostcode = $_POST["searchpostcode"];
}
$searchpostcode = mysql_real_escape_string($searchpostcode);
$searchaddress = mysql_real_escape_string($searchaddress);
$searchprojno = mysql_real_escape_string($searchprojno);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Search Projects</h4>
</div>
<div class="modal-body">
<form class="modal-form" id="searchform" name="searchform" action="" method="post">
<div class="form-group">
<label class="col-md-4 control-label">Project Number</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchprojno" id="searchprojno" placeholder="Enter Project Number">
</div>
<button type="submit" class="btn blue" id="submitsearchprojno" name="submitsearchprojno" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchaddress" id="searchaddress" placeholder="Enter Address">
</div>
<button type="submit" class="btn blue" id="submitsearchadd" name="submitsearchadd" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Postcode</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchpostcode" id="searchpostcode" placeholder="Enter Postcode">
</div>
<button type="submit" class="btn blue" id="submitsearchpc" name="submitsearchpc" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-advance table-hover">
<thead>
<tr>
<th class="col-md-9"><i class="fa fa-list-alt"></i> Address</th>
<th class="col-md-3"></th>
</tr>
</thead>
<tbody>
<tr>
<?php $searchrs = mysql_query("SELECT ProjectNo, CONCAT(COALESCE(HouseNoName, ''), ' ', COALESCE(StreetName, ''), ' ',
COALESCE(TownOrCity, ''), ' ', COALESCE(Postcode, '')) AS Display, PropID, AreaID, AWGMember, Householder, HouseNoName,
StreetName, TownOrCity, Postcode, ContactTelephone, AlternatePhone, Email, PropertyTenure, PropertyNotes
FROM prop_property
WHERE IsActive = 1
AND (Postcode = '".$searchpostcode."'
OR StreetName = '".$searchaddress."'
OR ProjectNo = '".$searchprojno."')
") or die(mysql_error());
$checkrs = mysql_query("SELECT * FROM prop_property WHERE IsActive = 0");
if(!mysql_num_rows($checkrs) > 0) {
echo '<td> No record found!</td><td></td>';
}
else {
while ($results = mysql_fetch_array($searchrs)) {
echo '
<td id="displayadd">'.$results['Display'].'</td>
<td>
<form action="../jobdetails.php" method="post">
<input type="hidden" name="searchhouse" value=" '.$results['HouseNoName'].'" >
<input type="hidden" name="searchstreet" value=" '.$results['StreetName'].'" >
<input type="hidden" name="searchtown" value=" '.$results['TownOrCity'].'" >
<input type="hidden" name="searchpostcode" value=" '.$results['Postcode'].'" >
<input type="hidden" name="searchpropid" value=" '.$results['PropID'].'" >
<input type="hidden" name="searchprojectno" value=" '.$results['ProjectNo'].'" >
<button type="submit" class="btn default btn-xs blue-stripe" id="viewsearch" name="viewsearch">View Address</button>
</form>
</td>';
}
}?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</form>
<div class="modal-footer right">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
</div>
<script type="text/javascript">
$(function(){
$('#searchform').on('submit', function(e){
e.preventDefault();
//alert($('#searchpostcode').val())
$.post('includes/jobdetailssearch.php',
$('#searchform').serialize(),
function(data, status){
$('.table-responsive #displayadd').html(data.Display);
//$("#table-responsive td").last().append(data);
console.log("done");
}).fail(function () {
console.log("fail");
});
});
});
</script>
How can I get it to POST the INPUT to the database and return in the table?

Bootstrap: Using a disabled button as a form input

There may be a better way to do this, but I'm trying to create a button group where the left and right buttons are increment/decrement, and the middle button is a disabled button representing the value.
The field properly increments/decrements, but the value isn't getting passed to php.
I do like how the button group looks:
HTML
<form method="POST" action="send_email.php">
<div class="row"">
<div class="col-sm-4 col-xs-4">
<h5><b>Attendees</b></h5>
</div>
<div class="col-sm-8 col-xs-8">
<div class="btn-group">
<input type="button" class="btn btn-default" name="decrease" value="-" onclick="decreaseBtnOnclick('attendees')"/>
<input type="button" class="btn btn-primary" name="attendees" value="0" id="chairs" disabled/>
<input type="button" class="btn btn-default" name="increase" value="+" onclick="increaseBtnOnclick('attendees')"/>
</div>
</div>
</div>
<div class="text-right">
<input type="hidden" name="email" value="contact">
<a href="./index.php">
<button type="submit" class="btn-main">Finish!</button>
</a>
</div>
</form>
Javascript (works fine to change the value in the middle button)
<script>
function increaseBtnOnclick(item) {
document.getElementById(item).value = Number(document.getElementById(item).value) + 1;
}
function decreaseBtnOnclick(item) {
if(document.getElementById(item).value > 0){
document.getElementById(item).value = Number(document.getElementById(item).value) - 1;
}
}
PHP (works fine for other types of inputs, e.g., text)
<?php
if(isset($_POST['email'])) {
$attendees = $_POST['attendees']; // required
echo "Attendees: ".$attendees;
}
?>
Try adding a hidden input then add the value of your disabled button to it with JS.
JS
function increaseBtnOnclick(item) {
var newValue = Number(document.getElementById(item).value) + 1;
document.getElementById(item).value = newValue;
document.getElementById("hidden_input").value = newValue;
}
function decreaseBtnOnclick(item) {
if(document.getElementById(item).value > 0){
var newValue = Number(document.getElementById(item).value) - 1;
document.getElementById(item).value = newValue;
document.getElementById("hidden_input").value = newValue;
}
}
HTML:
<form method="POST" action="send_email.php">
<div class="row"">
<div class="col-sm-4 col-xs-4">
<h5><b>Attendees</b></h5>
</div>
<div class="col-sm-8 col-xs-8">
<div class="btn-group">
<input type="button" class="btn btn-default" name="decrease" value="-" onclick="decreaseBtnOnclick('attendees')"/>
<input type="button" class="btn btn-primary" name="attendees" value="0" id="chairs" disabled/>
<input type="button" class="btn btn-default" name="increase" value="+" onclick="increaseBtnOnclick('attendees')"/>
<input type="hidden" name="hiddenvalue" id="hidden_input" value="0">
</div>
</div>
</div>
<div class="text-right">
<input type="hidden" name="email" value="contact">
<a href="./index.php">
<button type="submit" class="btn-main">Finish!</button>
</a>
</div>
</form>
PHP:
<?php
if(isset($_POST['email'])) {
$attendees = $_POST['hiddenvalue']; // required
echo "Attendees: ".$attendees;
}
?>
You could switch to a regular input field with button addons.
Disabled input fields do not get posted, however you can set it to readonly.
Please have a look at this thread,
Disabled form inputs do not appear in the request
You could use a hidden input field:
<input type="hidden" id="h_attendees" name="h_attendees" value="0"/>
In your increaseBtnOnclick and decreaseBtnOnclick you could set the value of the hidden field.
function increaseBtnOnclick(item) {
document.getElementById(item).value = Number(document.getElementById(item).value) + 1;
document.getElementById("h_attendees").value = document.getElementById(item).value;
}
function decreaseBtnOnclick(item) {
if(document.getElementById(item).value > 0){
document.getElementById(item).value = Number(document.getElementById(item).value) - 1;
document.getElementById("h_attendees").value = document.getElementById(item).value;
}
}
And access it in PHP
$_POST['h_attendees'];

Categories