I have two dynamic multi-selector form fields and I am trying to insert all records from the form into the database at once. Once selector is for the district and another one is a listing of data elements. For every district, there should be a record for each data element. So, if someone selects 2 districts and 3 data elements, 6 records should be inserted into the database. I appreciate any help anyone can provide. Thanks.
Here is my form code:
<form method="post" action="process.php" enctype="multipart/form-
data">
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search" class="form-control" size="15"
multiple="multiple">
<?php
while(!$category->atEnd()) { //dyn select
?>
<option value="<?php echo($category-
>getColumnVal("data_elementID")); ?>"><?php echo($category-
>getColumnVal("element_name")); ?></option>
<?php
$category->moveNext();
} //dyn select
$category->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search_rightAll" class="btn btn-block"><i
class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search_rightSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search_leftSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search_leftAll" class="btn btn-block"><i
class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="data_elementID[]" id="search_to" class="form-control"
size="15" multiple="multiple">
</select>
</div>
</div>
<p> </p>
<h4>Please select the district(s) that use this resource that you
would like to assign these data elements to:</h4>
<div class="row">
<div class="col-xs-5">
<select name="from[]" id="search2" class="form-control" size="15"
multiple="multiple">
<?php
while(!$districts_selected->atEnd()) { //dyn select
?>
<option value="<?php echo($districts_selected-
>getColumnVal("districtID")); ?>"><?php echo($districts_selected-
>getColumnVal("district_name")); ?></option>
<?php
$districts_selected->moveNext();
} //dyn select
$districts_selected->moveFirst();
?>
</select>
</div>
<div class="col-xs-2">
<button type="button" id="search2_rightAll" class="btn btn-block"><i
class="glyphicon glyphicon-forward"></i></button>
<button type="button" id="search2_rightSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-right"></i></button>
<button type="button" id="search2_leftSelected" class="btn btn-
block"><i class="glyphicon glyphicon-chevron-left"></i></button>
<button type="button" id="search2_leftAll" class="btn btn-block"><i
class="glyphicon glyphicon-backward"></i></button>
</div>
<div class="col-xs-5">
<select name="districtID[]" id="search2_to" class="form-control"
size="15" multiple="multiple">
</select>
</div>
</div>
<?php
$wa_startindex = 0;
while(!$category->atEnd()) {
$wa_startindex = $category->Index;
?>
<input name="softwareID[]" type="hidden" multiple="multiple" value="
<?php echo $_GET['softwareID']; ?>">
<?php
$category->moveNext();
}
$category->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
<br><br>
<input type="image" src="images/save.png" name="submit" id="submit"
alt="Save" />
</form>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#search').multiselect({
search: {
left: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
right: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
},
fireSearch: function(value) {
return value.length > 3;
}
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#search2').multiselect({
search: {
left: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
right: '<input type="text" name="q" class="form-control"
placeholder="Search..." />',
},
fireSearch: function(value) {
return value.length > 3;
}
});
});
</script>
Here is my insert code:
<?php
$dbh = new PDO("mysql:host=$hostname;dbname=mspa",$user,$pass);
?>
<?php
$array =
array($_POST['districtID'], $_POST['softwareID'],
$_POST['data_elementID']);
// pdo example
$sql = 'INSERT INTO district_data_elements (districtID, softwareID,
data_elementID) VALUES (:value1, :value2, :value3)';
// $dbh is pdo connection
$insertTable = $dbh->prepare($sql);
$countArray = count($array);
$i = 0;
while ($i < $countArray) {
$insertTable->bindParam(':value1', $array[1][$i], PDO::PARAM_INT);
// if value is int
$insertTable->bindParam(':value2', $array[2][$i], PDO::PARAM_STR);
// if value is str
$insertTable->bindParam(':value3', $array[3][$i], PDO::PARAM_STR);
$insertTable->execute();
$i++;
}
?>
Related
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.
Hello so I am having a slight problem at the moment Basically I have a while loop that outputs a table called job from database along with a bid button that links to bid.php. When the button takes me to the page I want it to carry over the jobid of the row that the button was clicked so I can enter the specific value into my database does anyone have any ideas on how to move over currently I am trying to do it using POST but I keep getting errors and the variable dosnt seem to be moving over.I just get a blank page and the id is not displayed.
Here is findjob22.php:
<?php
require 'config.php';
if(isset($_POST['submit']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `job` WHERE CONCAT(`job_id`,`location`, `description`, `budget`, `duedate`,`title`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `job`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$conn = mysqli_connect("localhost", "root", "", "bid4myjob");
$filter_Result = mysqli_query($conn, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html lang="en">
<!-- PAGE CONTENT -->
<div class="page-content page-search-result">
<div class="container">
<!-- Search Form -->
<form class="form form-horizontal" action="bid.php" method="post">
<div class="input-group input-group-lg">
<div class="input-group-btn">
<!--<select id="search-type-select" name="valueToSearch" class="multiselect multiselect-single-lg search-type-select">
<option value="all" selected="selected">All</option>
<option value="page">Page</option>
<option value="task">Task</option>
<option value="user">User</option>
<option value="image">Image</option>
</select>
</div>-->
<input class="form-control input-lg" type="text" name="valueToSearch" placeholder="type keyword ..." />
<span class="input-group-btn">
<button type="submit" name= "submit" value="Search" class="btn btn-primary btn-lg"><i class="icon ion-android-search"></i> Go</button>
</span>
</div>
</form>
<!-- End Search Form -->
</div>
</div>
<div>
<table>
<tr>
<th>id</th>
<th>Title</th>
<th>Location</th>
<th>Description</th>
<th>Budget</th>
<th>Due date</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<?php //$jid= $row['job_id']; ?>
<td><?php echo $row['job_id']; ?></td>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['description'];?></td>
<td><?php echo $row['price'];?></td>
<td><?php echo $row['duedate'];?></td>
<td><form method="post" action="bid.php" class="form-horizontal">
<?php //echo _("Enter ") . ' ' . $last_bid_plus . ' ' . _('or more'); ?>
<!--<div class="input-group ">
<input type="number" value="bid" class="form-control" name="bid" id= "bid" required/>
</div>
<br/>-->
<input type="submit" name="job_id" value="<?php $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">bid</input>
<br/>
</form></td>
</tr>
<?php endwhile;?>
</table>
</div>
<!-- END PAGE CONTENT -->
</body>
</html>
Here is bid.php where I am trying to get the specific id of the row from findjob22.php:
<?php
// include "job.php"
$jobid = $_POST['job_id'];
echo "$jobid"
?>
<!--<html>
<div class="col-xs-8">
<div class="page-header white-content">
<h1><?= _('Your Bid') ?>.</h1>
</div>
<div class="white-content">
<div class="well">
<br/><br/>
<form method="post" action="/listings/bid/<?//=$listingID; ?>/confirm" class="form-horizontal">
<input type="hidden" value="<?=//$bid_amount?>" class="input-medium" name="bid_amount"/>
<input type="submit" name="sb_bid" value="<?php// echo _('I agree and I confirm my BID'); ?>" class="btn btn-medium btn-green" />
</form>
</div>
</div>
</div>
</html>-->
I am not sure you can pass values in the submit button, but you can use a hidden input to pass the value.
<input type="hidden" value="<?php echo $row['job_id']; ?>" name="job_id" />
<input type="submit" class="btn btn-xlarge btn-block btn-primary">bid</input>
If you want it to work like you have it use a button.
<button type="submit"
name="job_id"
value="<?php echo $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">
bid
</button>
if you want to also pass some data:
<form method="post"
action="bid.php"
class="form-horizontal">
<div class="input-group">
<input type="text"
class="form-control"
name="bid"
id="bid" required />
</div>
<button type="submit"
name="job_id"
value="<?php echo $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">
bid
</button>
<br/>
</form>
Then you will have a $_POST["job_id"] and $_POST["bid"] in bid.php
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>
';
}
}
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?
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'];