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
Related
I have a signup form in which i have some input fields with placeholder text. I dont have any label for input field as i have placeholder. I want to shift placeholder text to up when user types writing.. What should i add to my css file to make it happen.
below image shows my signup form
my signup.php file:
<div class="loginForm">
<form action="signUp.php" method="POST">
<input type="text" name="firstName" placeholder="First name" autocomplete="off" required>
<input type="text" name="lastName" placeholder="Last name" autocomplete="off" required>
<input type="text" name="username" placeholder="Username" autocomplete="off" required>
<input type="email" name="email" placeholder="Email" autocomplete="off" required>
<input type="email" name="email2" placeholder="Confirm email" autocomplete="off" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<input type="password" name="password2" placeholder="Confirm password" autocomplete="off" required>
<input type="submit" name="submitButton" value="SUBMIT">
</form>
</div>
my css file that i have tried:
.signInContainer .column form input[type="text"],
.signInContainer .column form input[type="email"],
.signInContainer .column form input[type="password"] {
font-size: 14px;
margin: 10px 0;
border: none;
border-bottom: 1px solid #dedede;
box-shadow: none;
transition: all .8s;
}
.signInContainer .column form input[type="text"]:focus,
.signInContainer .column form input[type="email"]:focus,
.signInContainer .column form input[type="password"]:focus {
outline: none;
transform: translateY(-3px);
border-bottom: 1px solid #464646;
}
CSS solution: You'll need a label for that and a little bit of markup and a webkit browser.
.container {
position: relative;
padding-top: 25px;
margin-top: 10px;
}
.input-text {
padding: 10px 5px;
}
/* the second part of the trick is that you place your label to
look like a placeholder */
label.move-out {
position: absolute;
top: 35px;
left: 15px;
color: lightgrey;
transition: top 0.4s, left 0.4s
}
/* :placeholder-shown now works with an "empty" placeholder and a
correctly positioned label, and also keeps the label at position,
when data is in the input field */
/* :-webkit-autofill is there if Chrome wants to fill your input
box automatically */
input:focus+label.move-out,
input:not( :placeholder-shown)+label.move-out,
input:-webkit-autofill+label.move-out {
top: 0px;
left: 0px;
transition: top 0.4s, left 0.4s;
color: black;
}
<div class="container">
<!-- the first part of the trick is that you create an "empty"
placeholder attr -->
<input id="i1" class="input-text" type="text" placeholder=" " />
<label class="move-out" for="i1">Label 1</label>
</div>
<div class="container">
<!-- the first part of the trick is that you create an "empty"
placeholder attr -->
<input id="i2" class="input-text" type="text" placeholder=" " />
<label class="move-out" for="i2">Label 2</label>
</div>
It's important to place the label AFTER the input field, as CSS has a selector to select element after an other element (element + element), but there's no selector to select an element before an other.
You could have an empty label (which wouldn't show in the rendered output since it's empty) and when you type anything in the input, change the value of the label to the placeholder of your input.
document.getElementById("input_text").addEventListener("keydown", function() {
document.getElementById("text").innerHTML = document.getElementById("input_text").placeholder;
});
<label id="text"></label>
<input type="text" id="input_text" placeholder="Type here" />
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>
am making this form input in my HMVC project. i want to have
input type="date"
but it happens to be the output was just like a normal textbox. what other ways can i do this or what is the error?
add_view.php
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/bootstrap/css/inputfield.css">
<html>
<div>
<fieldset>
<?php
echo form_open('Clients/create');
?>
<p>
<label class="field" for=""><span>*</span>Name:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Details:</label>
<textarea name=""></textarea>
</p>
</br></br></br>
<p>
<label class="field" for=""><span>*</span>Address:</label>
<textarea name=""></textarea>
</p>
<p>
<label class="field" for=""><span>*</span>Contact Number:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Contact Email:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Date Added:</label>
<input type="date" name="" min="1950-01-01">
</p>
<?php
echo form_submit('submit','Save');
echo validation_errors();
echo form_close();
?>
</fieldset>
</div>
</html>
inputfield.css
textarea {
width: 51%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px black;
border-radius: 4px;
resize: none;
float:right;
}
fieldset {
width: 500px;
}
label .field{
text-align:left;
width:100px;
float:left;
font-weight: bold;
}
input.textbox-300{
width:350;
float:right;
}
fieldset p {
clear:both;
padding:5px;
}
label span, .required{
color:red;
font-weight: bold;
}
.center {
margin: auto;
padding: 10px;
}
im sorry im not good in this date thing so please help me
You are getting empty textbox result because you are not using name attribute in your input fields just add name attribute in all input fields as:
Example:
<input type = "text" name="yourName" class ="textbox-300">
<textarea name="Details"></textarea>
<textarea name="Address"></textarea>
<input type = "text" name="ContactNo" class ="textbox-300">
<input type = "text" name="Email" class ="textbox-300">
<input type="date" name="YourDate" min="1950-01-01">
date picker appears to be blank because it is not supported by mozilla fire fox. if theres any that mozilla supports please let me know. thanks
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 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>