I have a page that pulls from a database and shows rows of thumbnail pictures and a small bit of information about them. I have a "Read More" button for each person. But you need to sign in to be able to read more about that person.
When you press "Read More" a pop up window opens offering the user to either "sign in" (already have an account) or "create a new account".
After a user signs in I would like that page to redirect to the specific person's profile. My issue is I can't figure out where to store that id variable. How do I pass that variable to the popup window and then on to the redirect link.
// User Log In Form
if (isset($_POST['submit']) && $_POST['submit'] == 'userSignIn') {
if($_POST['usersEmail'] == '') {
$msgBox = alertBox("Your User Email Address is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else if($_POST['password'] == '') {
$msgBox = alertBox("Your Account Password is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else {
// Check if the User account has been activated
$usersEmail = (isset($_POST['usersEmail'])) ? $mysqli->real_escape_string($_POST['usersEmail']) : '';
$check = $mysqli->query("SELECT isActive FROM users WHERE usersEmail = '".$usersEmail."'");
$row = mysqli_fetch_assoc($check);
// If the account is active - allow the login
if ($row['isActive'] == '1') {
$usersEmail = $mysqli->real_escape_string($_POST['usersEmail']);
$password = encryptIt($_POST['password']);
if($stmt = $mysqli -> prepare("
SELECT
userId,
usersEmail,
usersName
FROM
users
WHERE
usersEmail = ? AND password = ?
")) {
$stmt -> bind_param("ss",
$usersEmail,
$password
);
$stmt -> execute();
$stmt -> bind_result(
$userId,
$usersEmail,
$usersName
);
$stmt -> fetch();
$stmt -> close();
if (!empty($userId)) {
session_start();
$_SESSION["userId"] = $userId;
$_SESSION["usersEmail"] = $usersEmail;
$_SESSION["usersName"] = $usersName;
$id = **NEED PERSON'S ID**
header("Location: http://scout.militarypropertyproject.com/index.php?page=scout_detail&id=".$id."");
} else {
$msgBox = alertBox("Login Failed. Please check your entries." , "<i class='fa fa-times-circle'></i>", "danger");
}
}
// Update Last Visited Date for User
$lastVisited = date("Y-m-d H:i:s");
$sqlStmt = $mysqli->prepare("
UPDATE
users
SET
lastVisited = ?
WHERE
userId = ?
");
$sqlStmt->bind_param('ss',
$lastVisited,
$userId
);
$sqlStmt->execute();
$sqlStmt->close();
} else if ($row['isActive'] == '0') {
// If the account is not active, show a message
$msgBox = alertBox("Your Account is currently inactive, and you can not log in.", "<i class='fa fa-warning'></i>", "warning");
} else {
// No account found
$msgBox = alertBox("No Account found for that Email Address & Password.", "<i class='fa fa-times-circle'></i>", "danger");
}
}
}
//////////////////// User's displayed in rows ////////////////////////////
<div class="row">
<div id="FilterContainer">
<?php foreach ($categories as $category) { ?>
<div class="col-md-4">
<div id = "user-square">
<div class="avatar">
<center> <img src="<?php echo '../'.$avatarDir.$category['usersAvatar']; ?>" class="publicAvatar" /></center>
</div>
<div class = "user_bio_heading"><?php echo $category['name']; ?>
<?php $starNumber = $category['avgstars'];
for($x=1;$x<=$starNumber;$x++) {
echo '<i class="fa fa-star"></i>';
}
if (strpos($starNumber,'.')) {
echo '<i class="fa fa-star-half"></i>';
$x++;
}
while ($x<=5) {
echo '<i class="fa fa-star-o"></i>';
$x++;
}
?>
</div>
<div class = "user_bio"><?php echo substr($category['bio'], 0, 150) ?>...
<?php $_SESSION["scoutUserId"] = $category['id'];
?>
</div>
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Read More</a>
</div>
</div>
<?php }
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- row -->
/////////////////////////////// POP UP WINDOW //////////////////////////
<div class="modal fade" id="signIn" tabindex="-1" role="dialog" aria-labelledby="newAccount" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header success">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title">Sign In</h4>
</div>
<form action="" method="post">
<p>All ready have a user account? Please Sign in.</p>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" class="form-control" required="" placeholder="User's Email Address" name="usersEmail" />
</div>
<br />
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock icon-lock"></i></span>
<input type="password" class="form-control" required="" placeholder="Account Password" name="password" />
</div>
<div class="row mt10">
<div class="col-md-4">
<p><small><a data-toggle="modal" href="#resetPassword">Reset Password?</a></small></p>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="captcha" value="" />
<button type="input" name="submit" value="userSignIn" class="btn btn-success btn-icon"><i class="fa fa-check-square-o"></i> Sign In</button>
<button type="button" class="btn btn-warning btn-icon" data-dismiss="modal"><i class="fa fa-times-circle"></i> Cancel</button>
</div>
<hr>
<p>Don't have an account with us yet? No worries we'll get you set up real quick!</p>
<button type="input" name="submit" value="newAccount" class="btn btn-success btn-icon"><i class="fa fa-check-square-o"></i> Create Account</button>
</form>
</div>
</div>
</div>
<div class="col-md-8">
<span class="pull-right">
<button type="input" name="submit" value="userSignIn" class="btn btn-success btn-sm btn-icon"><i class="fa fa-sign-in"></i> Sign In</button>
<a data-toggle="modal" href="#newAccount" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Create New Account</a>
</span>
</div>
</div>
</form>
///////////////////////////////////////////////
Thanks in advance for any help you can provide.
How about you pass the user's id in Javascript and then interject it as hidden field into the form so when user successfully logs in, you know where they want to go.
So first add new data attribute to this code:
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt"></i> Read More</a>
So it becomes (note data-uid):
<a data-toggle="modal" href="#signIn" class="btn btn-warning btn-sm btn-icon"><i class="fa fa-unlock-alt" data-uid="<?=$category['id']?>"></i> Read More</a>
Then in popup code where you have:
<input type="hidden" name="captcha" value="" />
You add new hidden input tag:
<input type="hidden" name="captcha" value="" />
<input id="wanted_user" type="hidden" name="userid" value="" />
Finally, in javascript modal popup code you interject the data-uid to the hidden field. You get the correct id by listening who triggered the event.
$('#signIn').on('show.bs.modal', function (e) {
var target_user = $(e.relatedTarget).data('uid');
$('#wanted_user').val(target_user);
});
Please note that this example might have some bugs and you need to debug it.
CodePen for you
Related
I got a problem with my login page.
<?php
session_start();
error_reporting(0);
include("include/config.php");
if(isset($_SESSION['captcha_code']) && isset($_POST['submit']))
{
if ($_SESSION['captcha_code'] == $_POST['captcha']) {
$ret=mysqli_query($con,"SELECT * FROM users WHERE email='".$_POST['email']."' and password='".md5($_POST['password'])."'");
$num=mysqli_fetch_array($ret);
if(mysqli_num_rows($ret) > 0) {
echo "<script>alert('Successfully Registered. You can login now');
window.location.href ='dashboard.php';</script>";
}
} else {
// CAPTCHA code is incorrect, show an error message and allow the user to try again
$_SESSION['errmsg']="Invalid email, password or CAPTCHA code";
$extra="user-login.php";
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
header("location:http://$host$uri/$extra");
}
exit();
}
?>
<html>
<div class="form-group">
<span class="input-icon">
<input type="text" class="form-control" name="email" placeholder="Email">
<i class="fa fa-user"></i> </span>
</div>
<div class="form-group form-actions">
<span class="input-icon">
<input type="password" class="form-control password" name="password" placeholder="Password">
<i class="fa fa-lock"></i>
</span><a href="forgot-password.php">
Forgot Password ?
</a>
</div>
<div class="form-actions">
<div class="form-group form-actions">
<img src="captcha.php" alt="Captcha Code" id="captchaImg">
<i class="fa fa-fresh"></i>
<input type="text" class="form-control" name="captcha" id = "captcha_code" placeholder="Enter above captcha">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary pull-right" name="submit">Login <i class="fa fa-arrow-circle-right"></i>
</button>
</div>
</html>
This page from my login.php. When the user clicks the submit button, the user is supposed to go to dashboard.php. In my case, it only generated a script alert but stayed on the login page. This happens when users insert a valid email, password, and captcha. I hope I can get a solution for this code. Thank you and sorry for my English.
How grab dynamic start_date & end_date form url to href after i click print?
enter image description here
When i click print, start_date & end_date always null
enter image description here
Here my Views:
<form action="/laporanstok/viewlaporanstok" method="get">
<div class="container align-items-center">
<div class="row">
<div class="col-6">
<div class="form-group">
<label class="font-weight-bold">Tanggal Mulai:</label>
<input type="date" id="start_date" name="start_date" class="form-control"
required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label class="font-weight-bold">Tanggal Akhir:</label>
<input type="date" id="end_date" name="end_date" class="form-control"
required>
</div>
</div>
<div class="container text-center">
<button type="submit" class="btn btn-success"><i class="fas fa-search"></i>
Cari</button>
<a href="{{ route('cetak_stok',['start_date'=>"
????",'end_date'=>"????"],) }}" target="_blank" class="btn
btn-primary"><i class="fas fa-print"></i>
Print</a>
<a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
Reset</a>
</div>
</div>
</div>
</form>
My Models:
class M_Laporan_Stok extends Model
{
use HasFactory;
protected $table = 'tbl_barang';
protected $primaryKey = 'id_barang';
protected $fillable = [
'id_proyek',
'kode_barang',
'nama_barang',
'tipe_barang',
'stok',
'created_at',
'updated_at'
];
}
My Controller:
public function print(Request $request)
{
$data = [
'title' => 'Cetak Stok',
'judul' => 'Halaman Cetak Stok',
'start_date' => $request->start_date,
'end_date' => $request->end_date,
];
return view('/content/laporan_stok/v_cetak_laporan_stok', $data);
}
My Route:
Route::get('/laporanstok/cetak', [LaporanStokController::class, 'print'])->name('cetak_stok');
Change this part of your code
<div class="container text-center">
<button type="submit" class="btn btn-success"><i class="fas fa-search"></i>
Cari</button>
<a href="{{ route('cetak_stok',['start_date'=>"
????",'end_date'=>"????"],) }}" target="_blank" class="btn
btn-primary"><i class="fas fa-print"></i>
Print</a>
<a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
Reset</a>
</div>
This way you have 2 submit buttons. Submitting form gets those dates you need.
<div class="container text-center">
<button type="submit" name="submit" class="btn btn-success"><i class="fas fa-search"></i>
Cari</button>
<button type="submit" name="print" class="btn btn-primary"><i class="fas fa-print"></i>
Print</button>
<a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
Reset</a>
</div>
In controller check what button was clicked.
if (isset($_POST['submit'])) {
//submit button was clicked
} else if (isset($_POST['print'])) {
//print button was clicked
} else {
//no button pressed
}
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]
i have not been able to get this, i have been on this for days ,i dont know if its from the login page or the dashboard , but my login script doesnt redirect to the dashboard
i have tried alot of things and even added an echo at every line of code , it shows that , the scripts get to the redirect and actually redirects but still comes back to the login page
<?php require 'sqlconnect.php' ?>
<?php
session_start();
?>
<?php
$email= '';
$password = '';
$errors = '';
$success = '';
if(isset($_REQUEST['login'])){
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
if(empty($email)){
$errors .= '<div class="alert alert-danger" role="alert">
Email field is empty.
</div>';
}
if(empty($password)){
$errors .= '<div class="alert alert-danger" role="alert">
Password field is empty.
</div>';
}
if(!empty($email) and !empty($password)){
$confirm_info = mysqli_query($connection, "SELECT * FROM users WHERE email = '$email' AND password = '$password'");
if(mysqli_num_rows($confirm_info) >= 1){
echo "if statement";
while($results = mysqli_fetch_assoc($confirm_info)) {
$token = $results['token'];
$token = $_SESSION['token'];
header("Location: dashboard/profile.php");
}
}else{
$errors .= '<div class="alert alert-danger" role="alert">
Login credentials doesn\'nt exist is our database.
</div>';
}
}
}
?>
</head>
<body>
<form class="login100-form validate-form" method="POST" action="login.php">
<span class="login100-form-title p-b-37">
Sign In
<!-- <i class="fa fa-home uk-align-center uk-text-center"></i> -->
</span>
<?php
echo $errors;
//echo $success;
?>
<br>
<div class="wrap-input100 validate-input m-b-20" data-validate="Enter username or email">
<input class="input100" type="email" name="email" placeholder="email" value="<?php echo $email ?>">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input m-b-25" data-validate = "Enter password">
<input class="input100" type="password" name="password" placeholder="password">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" id="login" name="login">
Sign In
<i class="fa fa-spinner fa-spin" id="spinner" style="display: none"></i>
</button>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
<a href="forgetpassword.php" class="txt2 hov1">
forget password
<i class="fa fa-long-arrow-right m-l-5"></i>
</a>
</span>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
Or Create an account
</span>
</div>
<!-- <div class="flex-c p-b-112">
<a href="#" class="login100-social-item">
<i class="fa fa-facebook-f"></i>
</a>
<a href="#" class="login100-social-item">
<img src="login/images/icons/icon-google.png" alt="GOOGLE">
</a>
</div> -->
<!--
<div class="text-center">
<a href="#" class="txt2 hov1">
Sign Up
</a>
</div> -->
</form>
<div class="container-login100-form-btn">
<a href="signup.php" class="txt2 hov1 text-light">
<button class="signin100-form-btn">
Sign Up
</button>
</a>
</div>
</div>
</div>
</body>
</html>
And this is the dashboard profile page code
<?php require '../sqlconnect.php' ?>
<?php
session_start();
$token = $_SESSION['token'];
if(!isset($_SESSION['token'])){
header("Location: ../login.php");
exit();
}else{
$all_details = mysqli_query($connection, "SELECT * FROM users WHERE token = '$token'");
if(mysqli_num_rows($all_details)){
$results = mysqli_fetch_assoc($all_details);
$id = $results['id'];
$token = $results['token'];
$email = $results['email'];
$first_name = $results['first_name'];
$is_admin = $results['is_admin'];
$last_name = $results['last_name'];
$usernam = $results['username'];
$image_name = $results['image_name'];
$image_dir = $results['image_dir'];
// echo $username;
}
}
?>
The characters that are not in PHP quote <?php ?> are treated as HTML output. And if the PHP page send any HTML output to the browser, the header would be sent at the same time. That's why any header() call after closing tag ?> would be useless.
You need to change your login page, or any page with header() calls to not close ?> before calling. For example:
<?php
require 'sqlconnect.php';
session_start();
$email= '';
$password = '';
$errors = '';
$success = '';
if(isset($_REQUEST['login'])){
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
if(empty($email)){
$errors .= '<div class="alert alert-danger" role="alert">
Email field is empty.
</div>';
}
if(empty($password)){
$errors .= '<div class="alert alert-danger" role="alert">
Password field is empty.
</div>';
}
if(!empty($email) and !empty($password)){
$confirm_info = mysqli_query($connection, "SELECT * FROM users WHERE email = '$email' AND password = '$password'");
if(mysqli_num_rows($confirm_info) >= 1){
echo "if statement";
while($results = mysqli_fetch_assoc($confirm_info)) {
$token = $results['token'];
$token = $_SESSION['token'];
header("Location: dashboard/profile.php");
}
}else{
$errors .= '<div class="alert alert-danger" role="alert">
Login credentials doesn\'nt exist is our database.
</div>';
}
}
}
?>
</head>
<body>
<form class="login100-form validate-form" method="POST" action="login.php">
<span class="login100-form-title p-b-37">
Sign In
<!-- <i class="fa fa-home uk-align-center uk-text-center"></i> -->
</span>
<?php
echo $errors;
//echo $success;
?>
<br>
<div class="wrap-input100 validate-input m-b-20" data-validate="Enter username or email">
<input class="input100" type="email" name="email" placeholder="email" value="<?php echo $email ?>">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input m-b-25" data-validate = "Enter password">
<input class="input100" type="password" name="password" placeholder="password">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn" id="login" name="login">
Sign In
<i class="fa fa-spinner fa-spin" id="spinner" style="display: none"></i>
</button>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
<a href="forgetpassword.php" class="txt2 hov1">
forget password
<i class="fa fa-long-arrow-right m-l-5"></i>
</a>
</span>
</div>
<div class="text-center p-t-57 p-b-20">
<span class="txt1">
Or Create an account
</span>
</div>
<!-- <div class="flex-c p-b-112">
<a href="#" class="login100-social-item">
<i class="fa fa-facebook-f"></i>
</a>
<a href="#" class="login100-social-item">
<img src="login/images/icons/icon-google.png" alt="GOOGLE">
</a>
</div> -->
<!--
<div class="text-center">
<a href="#" class="txt2 hov1">
Sign Up
</a>
</div> -->
</form>
<div class="container-login100-form-btn">
<a href="signup.php" class="txt2 hov1 text-light">
<button class="signin100-form-btn">
Sign Up
</button>
</a>
</div>
</div>
</div>
</body>
</html>
You'd need similar changes in the profile page, but you should have got the idea from the above example.
I think you reversed your variable assignment here:
while($results = mysqli_fetch_assoc($confirm_info)) {
$token = $results['token'];
$token = $_SESSION['token'];
header("Location: dashboard/profile.php");
}
This should be
while($results = mysqli_fetch_assoc($confirm_info)) {
$_SESSION['token'] = $results['token'];
header("Location: dashboard/profile.php");
}
In login page
while($results = mysqli_fetch_assoc($confirm_info))
{
$token = $results['token'];
$_SESSION['token'] = $token;
header("Location: dashboard/profile.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">