how to save previous page clikable url in database using php? - 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">

Related

The ajax is not getting the value?

I have the issue when clicking on the register button ,
is not getting the value,
I have made to many researchs i but cant find the answer,
Also i have all the libraries on the menu and
footer pages ,including jquery.
PHP CODE:
<?php
include 'Auth.php';
include 'partials/menu.php';
$usersObj = new Auth();
?>
<h2 class="mt-5 text-center mb-5">View Records
<button data-target="#Registration" data-toggle="modal" class="btn btn-primary" style="float:right;">Add New User</button>
</h2>
<!--Registration Modal-->
<div class="modal" id="Registration">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="text-dark">Add User Form</h3>
</div>
<div class="modal-body">
<p id="message" class="text-dark"></p>
<form>
<input type="text" class="user form-control my-2" placeholder="User Name" id="us">
<input type="text" class="form-control my-2" placeholder="User Email" id="fn">
<input type="password" class="form-control my-2" placeholder="User Password" id="pw">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" id="btn_register">Register Now</button>
<button type="button" class="btn btn-danger" data-dismiss="modal" id="btn_close">Close</button>
</div>
</div>
</div>
</div>
AJAX CODE:
<?php include 'partials/footer.php'; ?>
<script>
var username = $('#us').val();
var full_name = $('#fn').val();
var password =$('#pw').val();
$(document).on('click','#btn_register',function() {
console.log(username + full_name + password);
})
</script>
You are getting the values before the user enters them, you have to get them when the button is clicked, put your logic in the event handler.
<script>
$(document).on('click','#btn_register',function() {
var username = $('#us').val();
var full_name = $('#fn').val();
var password = $('#pw').val();
console.log(username + full_name + password);
})
</script>

saving data without reloading a page

I have a simple form in which a user can fill the form and can add multiple input fields as he/she wishes,
Here is HTML
<form id="paramsForms">
{{csrf_field()}}
<div class="modal-body">
<dvi class="container h-100">
<div class="d-flex justify-content-center">
<div class="card mt-5 col-md-12 animated bounceInDown myForm" id="multiple-container">
<div class="card-header">
<h4>Bidders Information</h4>
</div>
<div class="card-body" id="add_info">
<div id="dynamic_container">
<small id="bidder">Bidder 1</small>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
</div>
<input type="text" placeholder="Bidders Name" name="bidders_name[]" class="form-control"/>
</div>
<div class="input-group mt-3">
<div class="input-group-prepend">
<span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
</div>
<input type="text" placeholder="atribute name" name="params_name[]" id="field1" class="form-control"/>
<input type="number" placeholder="atribute value" name="params_value[]" id="field2" class="form-control"/>
<a class="btn btn-secondary btn-sm moreinput_field" id="add_more_input">
<i class="fa fa-plus-circle"></i>
</a>
</div>
</div>
</div>
<div class="card-footer" id="card-footer">
<a class="btn btn-success btn-sm" id="add_more"><i class="fa fa-plus-circle"></i> Add</a>
<!-- <button class="btn btn-success btn-sm float-right submit_btn"><i class="fas fa-arrow-alt-circle-right"></i> Submit</button> -->
</div>
</div>
</div>
</dvi>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
Here is js to save the form
$("#paramsForms").on('submit', function(e){
e.preventDefault();
$.ajax({
type:"POST",
url: "/parameters",
data: $("#paramsForms").serialize(),
success: function(response){
console.log(response)
alert('data saved');
},
error: function(error){
console.log(error)
alert('Data not saved');
}
})
})
Here is controller store function
public function store(Request $request)
{
$parameters = new Parameter;
$parameters->params_name = $request->input('params_name');
$parameters->params_value = $request->input('params_name');
$parameters->bidders_name = $request->input('bidders_name');
// dd($parameters);
$parameters->save();
}
The dd($parameters) in-store function gives the following.
So when I remove dd($parameters) and click submit button I get the following error on console (network).
message: "Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in C:\xampp\htdocs\roayalad-blog\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 869
What is wrong with my codes?
The issue is that you are sending params_name and params_name as an array but controller as handling as strings. Make this change in controller:
public function store(Request $request)
{
$parameters = new Parameter;
$record_count = count($request->input('params_name'));
for($i=0; $i<$record_count; $i++) {
$parameters->params_name = $request->input('params_name')[$i];
$parameters->params_value = $request->input('params_name')[$i];
$parameters->bidders_name = $request->input('bidders_name')[$i];
$parameters->save();
}
}
Above code will execute one query each record. You can also do bulk insertion. This is the link.
Try just
$request->params_name[$i]
Instead of
$request->input(“params_name”)[$i]

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

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.

Redirect to another page using radio buttons in php

I have a page with 2 pictures (that are in reality radio buttons) and a button "proceed" I can choose one picture or another but when I click on the "proceed" button it doesn't redirect.
Here is the code of my form and my php process page
<body>
<form method="post" action="process.php">
<div class="container">
<div class="row">
<div class="paymentCont">
<div class="headingWrap">
<h3 class="headingTop text-center">Choisissez votre méthode de paiement</h3>
<p class="text-center">Sélectionnez votre méthode puis cliquez sur "Continuer"</p>
</div>
<div class="paymentWrap">
<div class="btn-group paymentBtnGroup btn-group-justified" data-toggle="buttons">
<label class="btn paymentMethod">
<div class="method amex"></div>
<input type="radio" name="paiement" value="paysafecard">
</label>
<label class="btn paymentMethod">
<div class="method vishwa"></div>
<input type="radio" name="paiement" value="paypal">
</label>
</div>
</div>
<div class="footerNavWrap clearfix">
<div class="btn btn-success pull-left btn-fyi"> RETOURNER SUR LE SITE</div>
<div type="submit" class="btn btn-success pull-right btn-fyi" value="Continuer" />Continuer</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
</script>
</form>
</body>
And my php :
<?
if(isset($_POST['paiement']) && ($_POST['paiement']) == "paysafecard"){
header("Location: http://www.example.com/non_company.php");
}
elseif(isset($_POST['paiement']) && ($_POST['paiement']) == "")
{
header("Location: http://www.example.com/company.php");
}
else{
header("Location: http://www.example.com/redirect_to_home.php");
}
?>
I thought typical mistake, not a div tag it is button tag or input tag(type submit) will submit the page
Change the following
<div type="submit" class="btn btn-success pull-right btn-fyi" value="Continuer" />Continuer</div>
Into
<button type="submit" class="btn btn-success pull-right btn-fyi" value="Continuer" />Continuer</button>
In this case you should use:
<input type="submit" value="Continuer" />
Or a tag<button>Continuer</button>
Besides of <div type="submit" class="btn btn-success pull-right btn-fyi" value="Continuer">Continuer</div>
If you want to use a div you'll need to work with JS a make this div to submit

Trouble submitting echo'd form from another page

Page 1: It displays the form fine
<div id = "consult-form">
<?php include('consultation.php') ?>
</div>
Page 2: consultation.php
<div id="acordeon">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapseThree">
Consult Form
</a>
</h4>
</div>
<form action="postconsult.php" method="post" name ="consult-form" id="consult-form">
<div class = "col-md-8">
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
<h5>Why did you sign up?</h5>
<textarea class="form-control" name = "q1" id="q1"></textarea>
</div>
<h5>What are your goals?</h5>
<textarea class="form-control" name = "q2" id="q2"> </textarea>
<div class="footer text-center">
<button type="submit" class="btn btn-fill btn-success"
>Submit</button>
<button id="reset" class="btn btn-fill btn-danger" type="reset">Reset</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
postconsult.php
$comment = 'pleasework';
$last_id = mysqli_insert_id($conn);
$pbr = $conn->prepare("UPDATE `memberInfo` mi
INNER JOIN `loginInfo` AS li
ON li.userID = mi.UserID
SET `q1` = '$comment'
WHERE mi.userID = '1026'");
//mysqli_real_escape_string($conn, $q1);
//$pbr->bind_param("s", $comment);
$pbr->execute();
What I originally was trying was calling
<button type="submit" class="btn btn-fill btn-success" onClick="submitconsult();">Submit</button>
but it gave me the same problem as above
function submitconsult() {
// Returns successful data submission message when the entered information is stored in database.
var data = $('#consult-form').serialize();
$.ajax({
type: "POST",
url: "postconsult.php",
data: data,
cache: false,
success: function(html) {
//alert(html);
//document.getElementById('regform').reset();
}
});
}
If I go directly to consultation.php and hit submit it updates the database fine, but it doesn't work when I echo it.
What am I doing wrong?
Thanks
There are problem with id consult-form, there are 2 of them: one into first file and second into consultation.php. Try to change first file to something like this:
<div id = "consult-form-wrapper">
<?php include('consultation.php') ?>
</div>

Categories