I'm trying to add the user session to a table that is filled in when they complete a form. I would then like to display the form only they created on their home page.
<?php
require_once("/extlib/vdaemon/vdaemon.php");
require_once("./core/config.php");
?>
<html>
<head>
<style type="text/css">
body {
background: #e4e4e4;
}
.form {
width: 600px;
margin: 0 auto;
background: #fff;
padding: 45px;
border: 1px solid #c2c2c2;
}
.error {
color: #AA0000
}
.controlerror {
background-color: #ffffdd;
border: 1px solid #AA0000;
}
.input {
width: 300px;
height: 35px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="form">
<?php
$msg = $_GET['msg'];
if ( $msg == '1' ) {
echo '<p>Your information was submitted successfully.</p>';
}
?>
<form action="core/process.php" method="post" id="registration" >
<input type="hidden" name="formID" value="Product_Tracker" />
**<input type="hidden" name="id_user" value="$_SESSION['id_user']" />**
<p>Name of product:<input type="text" name="Name of Product" class="input" />
<p>Please select the tests that were done on the product.</p>
<p>In Circuit Test (ICT): Yes: <input type="radio" name="ICT" value="yes" /> No: <input type="radio" name="ICT" value="no" /></p>
<p>Visual Inspection: Yes: <input type="radio" name="Visual Inspection" value="yes" /> No: <input type="radio" name="Visual Inspection" value="no" /></p>
<p>XRAY: Yes: <input type="radio" name="XRAY" value="yes" /> No: <input type="radio" name="XRAY" value="no" /></p>
<p>Automated Optical Inspection (AOI): Yes: <input type="radio" name="AOI" value="yes" /> No: <input type="radio" name="AOI" value="no" /></p>
<!--<p>Checkbox1 <input type="checkbox" name="checkbox" value="checkbox1" /> Checkbox2: <input type="checkbox" name="checkbox" value="checkbox2" /></p>-->
<input type="submit" value="Submit" />
<p>
<a href='access-controlled.php'>Back</a>
</p>
</form>
</div>
</body>
</html>
<?php VDEnd(); ?>
When I look on phpMyAdmin when the form gets created the id_user is $_SESSION['id_user'] and not the name of the user that created it.
You didn't echo the value of $_SESSION['id_user'], Try this
<input type="hidden" name="id_user" value="<?php echo $_SESSION['id_user']"; ?> />
Related
I am going to start learn jquery with php.I have form(Which i copied from google)
$('document').ready(function() {
$('.toggleswitch').bootstrapToggle();
$("#check1 .stars").click(function() {
$(this).attr("checked");
});
});
/****** Rating Starts *****/
#import url(http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
fieldset,
label {
margin: 0;
padding: 0;
}
body {
margin: 20px;
}
h1 {
font-size: 1.5em;
margin: 10px;
}
.rating {
border: none;
float: left;
}
.rating>input {
display: none;
}
.rating>label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating>.half:before {
content: "\f089";
position: absolute;
}
.rating>label {
color: #ddd;
float: right;
}
.rating>input:checked~label,
.rating:not(:checked)>label:hover,
.rating:not(:checked)>label:hover~label {
color: #FFD700;
}
.rating>input:checked+label:hover,
.rating>input:checked~label:hover,
.rating>label:hover~input:checked~label,
.rating>input:checked~label:hover~label {
color: #FFED85;
}
/* Downloaded from http://devzone.co.in/ */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-toggle/2.2.2/js/bootstrap2-toggle.min.js"></script>
<form action="" method="POST" />
<fieldset id='check1' class="rating">
<input class="stars" type="radio" id="star_a-5" name="rating" value="5" />
<label class="full" for="star5" title="Awesome - 5 stars"></label>
<input class="stars" type="radio" id="star_a_5-half" name="rating" value="4.5" />
<label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input class="stars" type="radio" id="star_a-4" name="rating" value="4" />
<label class="full" for="star4" title="Pretty good - 4 stars"></label>
<input class="stars" type="radio" id="star_a_4-half" name="rating" value="3.5" />
<label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input class="stars" type="radio" id="star_a-3" name="rating" value="3" />
<label class="full" for="star3" title="Meh - 3 stars"></label>
<input class="stars" type="radio" id="star_a_3-half" name="rating" value="2.5" />
<label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input class="stars" type="radio" id="star2" name="rating" value="2" />
<label class="full" for="star2" title="Kinda bad - 2 stars"></label>
<input class="stars" type="radio" id="star1half" name="rating" value="1.5" />
<label class="half" for="star1half" title="Meh - 1.5 stars"></label>
<input class="stars" type="radio" id="star1" name="rating" value="1" />
<label class="full" for="star1" title="Sucks big time - 1 star"></label>
<input class="stars" type="radio" id="starhalf" name="rating" value="0.5" />
<label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
<br>
<input type="submit" onclick="setValue()" name="btn_submit" value="submit" />
</div>
using this PHP:
<?php
if(isset($_POST['btn_submit']))
{
echo '<pre>';
print_r($_POST);
}
?>
This form is working fine.If i click star rate and submit button I got output like
Array
(
[rating] => 1
[btn_submit] => submit
)
And if i am not select any rating output will be like
Array
(
[btn_submit] => submit
)
But i expect
Array
(
[rating] => 0
[btn_submit] => submit
)
I tried
function setValue()
{
var input = document.getElementById('check1');
if(input.value.length == '')
input.value = 0;
}
If i am not click star rate input field is set to 0?How can i do if i have more text input like check2 check3 check4 using jquery?I want to set all input text field as 0 before send data if rating is not clicked.Please help me?As a beginner please forgive if had make any mistake
This will not post as parameter to server, If you don't check any check-box
Additionaly you can check in PHP files, that is it posted or not.
Try
if(isset($_POST['btn_submit']))
{
$_POST['rating'] = isset($_POST['rating']) ? $_POST['rating'] : '0';
echo '<pre>';
print_r($_POST);
just add condition first in PHP like below
if(!isset($_POST['rating'])){
$_POST['rating'] = 0;
}
print_r($_POST);
Do not use the submit button to check the value - instead set the value and user the submit event of the form to check
I also had to remove the bootstrap which was not used AND change the IDs of the radios
When hitting the server you need to check that submit was set but no radio passed. Then that means 0 - right now my jQuery does not allow submission if not rated - I gave the form an ID
$('document').ready(function() {
$("#myForm").on("submit",function(e) {
if($("#check1 .stars:checked").length==0) {
alert("Please rate");
e.preventDefault();
}
})
});
/****** Rating Starts *****/
#import url(https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
fieldset,
label {
margin: 0;
padding: 0;
}
body {
margin: 20px;
}
h1 {
font-size: 1.5em;
margin: 10px;
}
.rating {
border: none;
float: left;
}
.rating>input {
display: none;
}
.rating>label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating>.half:before {
content: "\f089";
position: absolute;
}
.rating>label {
color: #ddd;
float: right;
}
.rating>input:checked~label,
.rating:not(:checked)>label:hover,
.rating:not(:checked)>label:hover~label {
color: #FFD700;
}
.rating>input:checked+label:hover,
.rating>input:checked~label:hover,
.rating>label:hover~input:checked~label,
.rating>input:checked~label:hover~label {
color: #FFED85;
}
/* Downloaded from http://devzone.co.in/ */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form id="myForm" action="" method="POST" />
<fieldset id='check1' class="rating toggleswitch">
<input class="stars" type="radio" id="star5" name="rating" value="5" data-toggle="toggle"/>
<label class="full" for="star5" title="Awesome - 5 stars"></label>
<input class="stars" type="radio" id="star4half" name="rating" value="4.5" data-toggle="toggle"/>
<label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input class="stars" type="radio" id="star4" name="rating" value="4" data-toggle="toggle"/>
<label class="full" for="star4" title="Pretty good - 4 stars"></label>
<input class="stars" type="radio" id="star3half" name="rating" value="3.5" data-toggle="toggle"/>
<label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input class="stars" type="radio" id="star3" name="rating" value="3" data-toggle="toggle"/>
<label class="full" for="star3" title="Meh - 3 stars"></label>
<input class="stars" type="radio" id="star2half" name="rating" value="2.5" data-toggle="toggle"/>
<label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input class="stars" type="radio" id="star2" name="rating" value="2" />
<label class="full" for="star2" title="Kinda bad - 2 stars"></label>
<input class="stars" type="radio" id="star1half" name="rating" value="1.5" data-toggle="toggle"/>
<label class="half" for="star1half" title="Meh - 1.5 stars"></label>
<input class="stars" type="radio" id="star1" name="rating" value="1" data-toggle="toggle" />
<label class="full" for="star1" title="Sucks big time - 1 star"></label>
<input class="stars" type="radio" id="starhalf" name="rating" value="0.5" data-toggle="toggle"/>
<label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
<br>
<input type="submit" name="btn_submit" value="submit" />
</div>
I have a register and login PHP script, that uses sessions and will display each users name when they log in. I also have a form that they can fill and is added to a mysql database. Is it possible so that only the user that filled in THEIR form can see it when its displayed? Currently whenever any user fills the form its displayed to every user.
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title></title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div id='fg_membersite_content'>
<h2>Product control page</h2>
<p>
Logged in as: <?= $fgmembersite->UserFullName() ?>
</p>
<p>Here you can see your Current Products:</p>
<?php
$con = mysql_connect("localhost","root","password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("trackerweb",$con);
$result = mysql_query("SELECT Name_of_Product FROM Product_Tracker");
while ($row = mysql_fetch_assoc($result)) {
echo $row['Name_of_Product'];
echo "<br />";
mysql_query($query);
}
mysql_close($con);
?>
<p>
<a href='add_customer.php'>Add a new product </a>
</p>
<p>
<a href='view.php'>View all product details</a>
</p>
<p>
<a href='login-home.php'>Home</a>
</p>
</div>
</body>
</html>
I only need to display the name of the product when they fill in the form on the same page.
This is the form:
<?php
require_once("/extlib/vdaemon/vdaemon.php");
require_once("./core/config.php");
$_SESSION['user']= ['$fgmembersite->UserFullName'];
?>
<html>
<head>
<style type="text/css">
body {
background: #e4e4e4;
}
.form {
width: 600px;
margin: 0 auto;
background: #fff;
padding: 45px;
border: 1px solid #c2c2c2;
}
.error {
color: #AA0000
}
.controlerror {
background-color: #ffffdd;
border: 1px solid #AA0000;
}
.input {
width: 300px;
height: 35px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="form">
<?php
$msg = $_GET['msg'];
if ( $msg == '1' ) {
echo '<p>Your information was submitted successfully.</p>';
}
?>
<form action="core/process.php" method="post" id="registration" >
<input type="hidden" name="formID" value="Product_Tracker" />
<p>Name of product:<input type="text" name="Name of Product" class="input" />
<p>Please select the tests that were done on the product.</p>
<p>In Circuit Test (ICT): Yes: <input type="radio" name="ICT" value="yes" /> No: <input type="radio" name="ICT" value="no" /></p>
<p>Visual Inspection: Yes: <input type="radio" name="Visual Inspection" value="yes" /> No: <input type="radio" name="Visual Inspection" value="no" /></p>
<p>XRAY: Yes: <input type="radio" name="XRAY" value="yes" /> No: <input type="radio" name="XRAY" value="no" /></p>
<p>Automated Optical Inspection (AOI): Yes: <input type="radio" name="AOI" value="yes" /> No: <input type="radio" name="AOI" value="no" /></p>
<!--<p>Checkbox1 <input type="checkbox" name="checkbox" value="checkbox1" /> Checkbox2: <input type="checkbox" name="checkbox" value="checkbox2" /></p>-->
<input type="submit" value="Submit" />
<p>
<a href='access-controlled.php'>Back</a>
</p>
</form>
</div>
</body>
</html>
<?php VDEnd(); ?>
<form name="reg" action="signup.php" onsubmit="return validateForm()" method="post" class="address"style="text-align:left; padding:0px 0px; position: relative; margin-top:30px">
<br /><br />
<span>Name</span><input type=text name="name" id="name"><br /><br />
<span>Age</span><input type="number" name="age" id="age"><br /><br />
<span>Gender</span><input type="radio" name="gender" id="gender" value="male">Male<input type="radio" name="gender" id="gender" value="female">Female<br /><br />
<span>Address</span><input type=text name="address" id="address"></br></br>
<span>Email id</span><input type="email" name="email" id="email"><br /><br />
<span>Contact No.</span><input type="number" name="contact" id="contact"></br></br>
<span>User type</span><input type="radio" name="roles" value="doctor">doctor<input type="radio" name="roles" value="patient" checked="checked">patient
<input type="radio" name="roles" value="admin">admin</br></br>
<input type="submit" class="button1">
</form>
how to float the slider to the right side of the page. what attributes should be added?
You need to add : float: right; to the style of #hislider1
how about float:right?
#hslider1 {
float:right;
}
you forgot to turn off the div tag. and also add float:right; in your #hislider1 div Change your code like this :
<div id="hislider1" style=" max-width:300px;max-height:300px; height:100%; float:right;">
<form name="reg" action="signup.php" onsubmit="return validateForm()" method="post" class="address"style="text-align:left; padding:0px 0px; position: relative; margin-top:30px">
<br /><br />
<span>Name</span><input type=text name="name" id="name"><br /><br />
<span>Age</span><input type="number" name="age" id="age"><br /><br />
<span>Gender</span><input type="radio" name="gender" id="gender" value="male">Male<input type="radio" name="gender" id="gender" value="female">Female<br /><br />
<span>Address</span><input type=text name="address" id="address"></br></br>
<span>Email id</span><input type="email" name="email" id="email"><br /><br />
<span>Contact No.</span><input type="number" name="contact" id="contact"></br></br>
<span>User type</span><input type="radio" name="roles" value="doctor">doctor<input type="radio" name="roles" value="patient" checked="checked">patient
<input type="radio" name="roles" value="admin">admin</br></br>
<input type="submit" class="button1">
</form>
</div>
The given code works in firefox, but not in any other browser.
Am i going about it wrong by using radio button
I just want 3 buttons but styled as i have already, when the user clicks an option its highlighted
Here is my Code :
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title></title>
</head>
<style>
.radio > input[type=radio]{
display:none;
visibility:hidden;
}
input[type=radio] + label{
cursor:pointer;
}
input[type=radio]:checked + label{
background-color:green;
}
.but1{
background-color:#009;
color:#FFF;
border:none;
border-radius:15px;
width:200px;
height:50px;
font-size:18px;
font-weight:bold;
border-radius:15px;
text-align:center;
padding:8px;
font-family:Verdana, Geneva, sans-serif;
float:left;
margin-left:10px;
}
</style>
</head>
<body>
<form action="Untitled2.php" method="post">
<label class="radio" for="fb1">
<input id="fb1" type="radio" name="time" value="all day" checked />
<label class="but1">Available<br>All day</label>
</label>
<label class="radio" for="fb2">
<input id="fb2" type="radio" name="time" value="between 8-12"/>
<label class="but1">Between<br>8am - 12am</label>
</label>
<label class="radio" for="fb3">
<input id="fb3" type="radio" name="time" value="between 12-4" />
<label class="but1">Between<br>12pm - 4pm</label>
</label>
<input name="submit" type="submit" />
</form>
</body>
</html>
How can i do this ?
Your outer label is redundant, you can instead do it this way:
<input id="fb1" type="radio" name="time" value="all day" checked />
<label class="but1" for="fb1">Available<br>All day</label>
<input id="fb2" type="radio" name="time" value="between 8-12"/>
<label class="but1" for="fb2">Between<br>8am - 12am</label>
<input id="fb3" type="radio" name="time" value="between 12-4" />
<label class="but1" for="fb3">Between<br>12pm - 4pm</label>
Also the css for hiding your radio button was wrong, should be just:
input[type=radio]{
display:none;
}
Fiddle
Updated , Please check the url
Used jQuery as you mentioned http://jsfiddle.net/VE9Tf/4/
<label class="radio" for="fb1">
<input id="fb1" type="radio" name="time" value="all day" checked />
<span class="but1 active">Available<br>All day</span>
</label>
<label class="radio" for="fb2">
<input id="fb2" type="radio" name="time" value="between 8-12"/>
<span class="but1">Between<br>8am - 12am</span>
</label>
<label class="radio" for="fb3">
<input id="fb3" type="radio" name="time" value="between 12-4" />
<span class="but1">Between<br>12pm - 4pm</span>
</label>
I have the following code :
<div id="choices">
<div>
<input type="radio" name="question-answers" id="question-answers-A" value="A" onclick="this.form.submit();" />
<label for="question-answers-A">$c[0] </label>
</div>
<div>
<input type="radio" name="question-answers" id="question-answers-B" value="B" onclick="this.form.submit();"/>
<label for="question-answers-B">$c[1]</label>
</div>
</div>
The form is submitted when a radio is selected.
Is there a way to do it without javascript? (without onClick)
Thanks.
Why not the traditional submit input ?
<form>
<input type="radio" name="r1">
<input type="radio" name="r2">
<input type="submit" value="send" />
</form>
The form is submitted when a radio is selected.
Javascript is the way to go or plain old html but it will not be submitted on change.
There is no way to detect when a radio button is clicked without using Javascript.
Here's an example of getting it to work without Javascript http://jsfiddle.net/DCHaT/8/
You rely on CSS and labels.
CSS:
button.transparent{
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
visiblity:hidden;
border:none;
z-index:2;
background-color:transparent;
}
div.radio{
position:relative;
}
div.radio > label > input[type="radio"]{
position:relative;
z-index:1;
}
Code:
<form action="http://www.yahoo.com" method="GET">
<div class="radio">
<label for="radio_1">
<button type="submit" class="transparent" name="radio" value="1"></button>
<input type="radio" value="1" name="radio" id="radio_1"/>
Radio 1</label>
</div>
<div class="radio">
<label for="radio_2">
<button type="submit" class="transparent" name="radio" value="2"></button>
<input type="radio" value="2" name="radio" id="radio_2"/>
Radio 2</label>
</div>
</form>
You could use php
<div class="field form-inline radio">
<label class="radio" for="txtContact">Preferred Method of Contact</label>
<input class="radio" type="radio" name="contact" value="email" checked /> <span>Email</span>
<input class="radio" type="radio" name="contact" value="phone" /> <span>Phone</span>
</div>
$contact = $_POST['contact']
//Will return either "email" or "phone".
Use two submit buttons, and optionally style them to look like radio buttons. http://jsfiddle.net/trevordixon/FNzhb/3/
<form method="POST">
<button type="submit" name="question-answers" value="A">A</button>
<button type="submit" name="question-answers" value="B">B</button>
</form>
<style>
button {
border: none;
background: none;
padding-left: 10px;
cursor: pointer;
}
button:before {
content: '';
display: block;
width: 12px;
height: 12px;
border: 1px solid #999;
border-radius: 50%;
}
button:active:before { content: '•'; }
</style>