I have tried so many times in different ways to solve this. Every time it generates the same output. I searched in [http://google.com] and [http://youtube.com] and followed many tutorials, and implemented my code according them..Their code runs properly but my code gives unknown output, though their code and my code is same.
This is the PHP code:
if(!isset($_POST["radio"])){
$radioMsg="You must Select a Category!";
}
if(isset($_POST["radio"])){
$radio=$_POST["radio"];
}
There is the radio Buttons
<form method="post" action="register.php" enctype="multipart/form-data"
style="width: 860px;margin: 0px;height: 580px;">
<input class="form-control" type="" name="name" placeholder="Name..."/
style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="email" name="email"
placeholder="Email..."/ style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="password" name="password"
placeholder="Password"/ style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="password" name="cPassword"
placeholder="
confirm Password..."/ style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="text" name="contactNO"
placeholder="Your
contact No.."/ style="width: 400px; margin-left: 200px" ><br>
<input type="file" name="image"/ style="width: 400px; margin-left:
200px">
<br><br>
<div style="border: 1px solid #4C6A6D;width: 250px;margin-left: 200px" >
<?php echo $radioMsg ?>
<h6 style="margin-left: 20px">Select a Cetagory</h6>
<input type="radio" name="radio" value="customer" style="margin-left:
25px">Customer<br>
<input type="radio" name="radio" value="DespensaryOwner" style="margin-
left:
25px">Despensary Owner<br>
input type="radio" name="radio" value="dealer" style="margin-left:
25px">Dealer<br>
</div>
<br>
<input class="btn-primary" type="submit" name="submit" value="Register"
style=" margin-left: 200px"><br><br>
</form>
if select radioButton1, it returns a value "radio" instead of value "customer"
Input type cannot be "cust":
<input type="radio" name="g" value="customer" style="margin-left:
25px">Customer<br>
<input type="radio" name="g" value="DespensaryOwner" style="margin-left:
25px">Despensary Owner<br>
<input type="radio" name="g" value="dealer" style="margin-left:
25px">Dealer<br>enter code here
Try code above and see if that works, also you should use better name values as suggested in the comments of this answer
I went ahead and ran this locally, by putting it all in a file called "register.php" in the root of a PHP dev server instance, with the PHP code at the top. In that situation, it spits out the error until a valid value is put in, but I imagine you're handling things differently.
I had to remove a number of strange forward slashes and line returns in your HTML, there were missing < and >, and your radio buttons were all named "radio", but after correcting those errors, the code below works:
PHP: (Included PHP tags for completeness)
<?php
if(!isset($_POST["category"])){
$radioMsg="You must Select a Category!";
}
if(isset($_POST["category"])){
$radioMsg="";
$radio=$_POST["category"];
}
?>
HTML: (Included entire html layout for completeness.)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="register.php" enctype="multipart/form-data" style="width: 860px;margin: 0px;height: 580px;">
<input class="form-control" type="" name="name" placeholder="Name..." style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="email" name="email" placeholder="Email..." style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="password" name="password" placeholder="Password" style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="password" name="cPassword" placeholder="confirm Password..." style="width: 400px; margin-left: 200px" ><br>
<input class="form-control" type="text" name="contactNO" placeholder="Your contact No.." style="width: 400px; margin-left: 200px" ><br>
<input type="file" name="image" style="width: 400px; margin-left: 200px">
<br><br>
<div style="border: 1px solid #4C6A6D;width: 250px;margin-left: 200px" >
<?php echo $radioMsg ?>
<h6 style="margin-left: 20px">Select a Category</h6>
<input type="radio" name="category" value="customer" style="margin-left: 25px">Customer<br>
<input type="radio" name="category" value="DispensaryOwner" style="margin-left: 25px">Dispensary Owner<br>
<input type="radio" name="category" value="dealer" style="margin-left: 25px">Dealer<br>
</div>
<br>
<input class="btn-primary" type="submit" name="submit" value="Register"
style=" margin-left: 200px"><br><br>
</form>
</body>
</html>
Related
I have created a form to which I am passing the data. When I try to echo the data it shows couple of errors saying that index is undefined.
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method='post' enctype='multipart/form-data'>
<input id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input id="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input id="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px; " name='Submit' value='Add Member' /><br><br>
</form>
</div>
</div>
<?php
if(isset($_POST['insert']))
{
echo $namevar = isset($_POST['name']);
echo $descriptionvar = isset($_POST['description']);
echo $designationvar = isset($_POST['designation']);
}
?>
Following are the errors:
Notice: Undefined index: name in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: description in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: designation in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
<form method='post' enctype='multipart/form-data'>
<input name="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input name="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input name="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px;" value='Add Member' /><br><br>
</form>
<?php
if(isset($_POST['insert']))
{
echo $namevar = $_POST['name'];
echo $descriptionvar = $_POST['description'];
echo $designationvar = $_POST['designation'];
}
?>
The issue is with the names of input fields.
In PHP or any other programming language, You should use the input name="something" to get the input values.
You should give the name for each input fields.
For example,
<input name = "name" id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
You cannot pass POST data to another page vie using ID.
You should give name to <input>
<input name="name">
<input name="description">
<input name="designation">
Edit
You are defining variables and echoing them same time
Change your code to:
<?php
if(isset($_POST["insert"])){
echo $_POST["name"];
echo $_POST["description"];
echo $_POST["designation"];
}?>
So I'm using CSS to reveal different text boxes based on what radio button gets clicked. It is working mostly, but I'll list the issues at the bottom below my code.
CSS:
.reveal-if-active {
opacity: 0;
max-height: 0;
overflow: hidden;
font-size: 16px;
-webkit-transform: scale(0.8);
transform: scale(0.8);
-webkit-transition: 0.5s;
transition: 0.5s;
}
.reveal-if-active label {
display: block;
margin: 0 0 3px 0;
}
.reveal-if-active input[type=text] {
width: 50%;
}
input[type="radio"]:checked ~ .reveal-if-active, input[type="checkbox"]:checked ~ .reveal-if-active {
opacity: 1;
max-height: 100px;
padding: 10px 20px;
-webkit-transform: scale(1);
transform: scale(1);
overflow: visible;
}
Form:
<h1>What group does this person belong to?</h1>
<br />
<form action="uploaderPerson.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_GET["id"]; ?>"/>
<input type="hidden" name="action" value="2"/>
<input type="radio" name="option" value="Employer" id="Employer"> Employer<br>
<div class="reveal-if-active">
<label for="empname">Employer's Name: </label>
<input type="text" id="empname" name="empname" class="require-if-active" data-require-pair="#Employer" placeholder="empname">
<label for="email">Employer's Email: </label>
<input type="text" id="email" name="email" class="require-if-active" data-require-pair="#Employer" placeholder="email">
<label for="phone">Employer's Phone: </label>
<input type="text" id="phone" name="phone" class="require-if-active" data-require-pair="#Employer" placeholder="phone">
</div>
<br />
<input type="radio" name="option" value="Faculty"> Faculty<br>
<div class="reveal-if-active">
<label for="hiredate">Hire Date: </label>
<input type="text" id="hiredate" name="hiredate" class="require-if-active" data-require-pair="#Faculty" placeholder="hiredate">
<label for="isretired">Retired?: </label>
<input type="text" id="isretired" name="isretired" class="require-if-active" data-require-pair="#Faculty" placeholder="isretired">
<label for="degreeinstitute">Degree Institute: </label>
<input type="text" id="degreeinstitute" name="degreeinstitute" class="require-if-active" data-require-pair="#Faculty" placeholder="degreeinstitute">
</div>
<br />
<input type="radio" name="option" value="Student"> Student<br>
<div class="reveal-if-active">
<label for="graduation">Hire Date: </label>
<input type="date" id="graduation" name="graduation" class="require-if-active" data-require-pair="#Student" placeholder="mm/dd/yyyy">
</div>
<br /><br />
<input type="submit" value="Submit">
</form>
My problem is when I click one radio button they all appear. I then click the Faculty button and Employer one goes away but the Student one stays active. Then I click the student one and the Faculty one finally disappears. Its not a huge deal, but I can't figure out what I'm missing. I'd imagine its something simple, but I can't seem to find it anywhere. I know several people use javascript to help with this kind of thing, but I wasn't having much luck using it and got this to work mostly. Any input is appreciated.
You are using the wrong CSS selector.
There is a way to do this with pure CSS as long as you strictly abide by some rules:
a) You need to use the + selector in order to select a direct sibling.
b) You need to be sure that your .reveal-if-active is a direct sibling to your checkbox which controls it.
CSS is not meant to do these tasks and I strongly advise against using CSS to achieve these results since it heavily relies on details in the DOM document which you may need to alter to achieve other styling requirements. However if it needs to be pure CSS you can do the following:
CSS
.reveal-if-active {
opacity: 0;
max-height: 0;
overflow: hidden;
font-size: 16px;
-webkit-transform: scale(0.8);
transform: scale(0.8);
-webkit-transition: 0.5s;
transition: 0.5s;
}
.reveal-if-active label {
display: block;
margin: 0 0 3px 0;
}
.reveal-if-active input[type=text] {
width: 50%;
}
input[type="radio"]:checked + .reveal-if-active, input[type="checkbox"]:checked + .reveal-if-active {
opacity: 1;
max-height: 100px;
padding: 10px 20px;
-webkit-transform: scale(1);
transform: scale(1);
overflow: visible;
}
HTML
<form action="uploaderPerson.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="id"/>
<input type="hidden" name="action" value="2"/>
<input type="radio" name="option" value="Employer" id="Employer"> Employer
<div class="reveal-if-active">
<label for="empname">Employer's Name: </label>
<input type="text" id="empname" name="empname" class="require-if-active" data-require-pair="#Employer" placeholder="empname">
<label for="email">Employer's Email: </label>
<input type="text" id="email" name="email" class="require-if-active" data-require-pair="#Employer" placeholder="email">
<label for="phone">Employer's Phone: </label>
<input type="text" id="phone" name="phone" class="require-if-active" data-require-pair="#Employer" placeholder="phone">
</div>
<br />
<input type="radio" name="option" value="Faculty"> Faculty
<div class="reveal-if-active">
<label for="hiredate">Hire Date: </label>
<input type="text" id="hiredate" name="hiredate" class="require-if-active" data-require-pair="#Faculty" placeholder="hiredate">
<label for="isretired">Retired?: </label>
<input type="text" id="isretired" name="isretired" class="require-if-active" data-require-pair="#Faculty" placeholder="isretired">
<label for="degreeinstitute">Degree Institute: </label>
<input type="text" id="degreeinstitute" name="degreeinstitute" class="require-if-active" data-require-pair="#Faculty" placeholder="degreeinstitute">
</div>
<br />
<input type="radio" name="option" value="Student"> Student
<div class="reveal-if-active">
<label for="graduation">Hire Date: </label>
<input type="date" id="graduation" name="graduation" class="require-if-active" data-require-pair="#Student" placeholder="mm/dd/yyyy">
</div>
<br /><br />
<input type="submit" value="Submit">
</form>
Example jsFiddle
You are going to want this example I think. It shows how to use javascript to hide and show your checkboxes, you just may need a few more ifs in there
EDIT: To use it, you are going to want to give your checkboxes ids that javascript/JQuery can grab
I have a form which I need it to insert data using the URL first for a few fields. I've attached a sample of my form below. We're posting it using PHP into a mySQL database. I don't mind how it gets in there. But i've seen examples using example.com/form.php?add_1=10 The Street, which would be the best way for me.
Thanks,
<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">
<input type="text" class="form-control" id="lastname" name="surname" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_1" name="add1" placeholder="Address Line 1" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_2" name="add2" placeholder="Address Line 2" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_3" name="add3" placeholder="Address Line 3" required style="
height: 35px;
">
<input type="text" class="form-control" id="postcode" name="postcode" placeholder="Postcode" required style="
height: 35px;
">
<input type="text" class="form-control" id="phone_number" name="phoneNum" placeholder="Phone Number" required style="
height: 35px;
">
</form>
I've already tried a javascript solution on here, but I couldn't seem to get it to do anything.
<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">
<input type="text" class="form-control" id="add_1" name="add1" value="<?php echo $_GET['add1']; ?>" placeholder="Address Line 1" required style="height: 35px;">
</form>
Now your URL must work!
http://example.com/form.php?add_1=10
What you need is this: http://www.php.net/manual/en/reserved.variables.get.php
http://urlToYourScript.php?add1=Randomstreet
<input type="text" class="form-control" id="add_1" name="add1"
placeholder="<?php echo $_GET['add1']; ?>" required style="height: 35px;">
I wanted to make a search form with GET but there seems to be a problem. The page you are looking at has other GET values too but it seems that the GET method clears the URL from variabels en goes like "?q=SEARCH" instead of "?p=Test&u=Bart&q=SEARCH".
This is the form code I'm using:
<form method="GET" action="test.php?p=glistentries&maingroup=<? echo $MainGroupID ?>&subgroup=<? echo $SubGroupID ?>">
<input type="text" class="form-control" id="focusedinput" value="<? echo $_GET['q']; ?>"
name="q" autocomplete="off" class="col-sm-4 control-label" placeholder="Search...">
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
</form>
Solved It
Thanks guys, forgot I can simply do this with hidden fields
Add the additional GET vars as hidden inputs:
<input type="hidden" name="p" value="Test">
Use input type hidden :
<form method="GET" action="test.php">
<input type="text" class="form-control" id="focusedinput" value="<? echo $_GET['q']; ?>" name="q" autocomplete="off" class="col-sm-4 control-label" placeholder="Search...">
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>
<input type="hidden" name="p" value="glistentries" />
<input type="hidden" name="maingroup" value="<? echo $MainGroupID ?>" />
<input type="hidden" name="subgroup" value="<? echo $SubGroupID ?>" />
</form>
I'm having a step down issue with my registration form, I've tried everything I can find on google but nothing works.
My DOB section is split into 3 different input boxes, I'm trying to get the right column up beside the left but as soon as I put any styling on it, the year section steps down.
I've tried so many different variations; Float, display, nothing works. Also I've added extra boxes and it's always after the first 2 boxes the step down happens.
When I try to style, notice the year step down:
Always steps down after 2 no matter what order:
HTML code:
<div id="regforms">
<form method="post" action="register.php" name="registerform" id="registerform">
<fieldset2>
<div id="regforms1">
<label for="username"></label><input type="text" name="username" id="username" placeholder="Username"/><br />
<label for="password"></label><input type="password" name="password" id="password" placeholder="Password"/><br />
<label for="email"></label><input type="text" name="email" id="email" placeholder="Email"/><br />
<input type="submit" name="register" id="login" value="Register" />
</div>
<div id="regforms2">
<label for="name"></label><input type="text" name="name" id="name" placeholder="Name"/><br />
<div id="dob">
<label for="dobm"><input type="text" name="month" id="month" placeholder="MM"/><br />
<label for="dobd"><input type="text" name="day" id="day" placeholder="DD"/><br />
<label for="dobd"><input type="text" name="day" id="day" placeholder="DD"/><br />
<label for="dobd"><input type="text" name="day" id="day" placeholder="DD"/><br />
<label for="doby"><input type="text" name="year" id="year" placeholder="YYYY"/><br />
</div>
</div>
</fieldset3>
</form>
</div>
CSS:
#regforms {
margin-top:200px;
border: 0;
display:block;
width:600px;
}
#regforms1 {
padding-right:25px;
width:275px;
float:left;
}
#regforms2 {
width:275px;
float:right;
}
#dob {
}
#month{
width:5%;
margin-right:5px;
}
#day{
width:10%;
margin-right:5px;
}
#year{
width:10%;
margin-right:5px;
}
As Aligarian said, you just need to remove the <br/> tag, although you don't seem to be closing the <label> tags in the DOB fields; you should close them.