Bootstrap radio button already checked not worked - php

This is my code of radio button i want image radio buttton is alredy check but it's not working
<div class="col-md-4" style="padding-top: 24px;" >
<label>Visual</label>
<div>
<label class="radio-inline">
<input type="radio" value="image" checked="checked" name="media_option[]" class="media_option" autocomplete="off"><?php echo __('Image') ?>
</label>
<label>or</label>
<label class="radio-inline">
<input value="video" type="radio" name="media_option[]" class="media_option" autocomplete="off" ><?php echo __('Video') ?>
</label>
</div>

Try this.
Don't set radio name as array and not need to set autocomplete attribute.
<div class="col-md-4" style="padding-top: 24px;" >
<label>Visual</label>
<div>
<label class="radio-inline">
<input type="radio" value="image" name="media_option" class="media_option" checked="checked" ><?php echo __('Image') ?>
</label>
<label>or</label>
<label class="radio-inline">
<input value="video" type="radio" name="media_option" class="media_option" ><?php echo __('Video') ?>
</label>
</div>

Its working fine, check here:
<input type="radio" value="image" checked="checked" name="media_option[]" class="media_option" autocomplete="off">One
<input type="radio" value="image" checked="checked" name="media_option[]" class="media_option" autocomplete="off">Two
when you are using radio, only one radio can be selected within one group (having same name). The same is working here.

How about this?
This will always work
<input type="radio" value="image" checked="checked" name="media_option[]" class="media_option" autocomplete="off">
If not try this
<input checked type="radio" value="image" name="media_option[]" class="media_option" autocomplete="off">

Just change the checked="checked" to checked only :
Here is the code ,please try:
<div class="col-md-4" style="padding-top: 24px;" >
<label>Visual</label>
<div>
<label class="radio-inline">
<input type="radio" value="image" checked name="media_option[]" class="media_option" autocomplete="off"><?php echo __('Image') ?>
</label>
<label>or</label>
<label class="radio-inline">
<input value="video" type="radio" name="media_option[]" class="media_option" autocomplete="off" ><?php echo __('Video') ?>
</label>
/div>

I came here because I had the same issue and without seeing the rest of the code in the question, won't make any assumptions.
However, if the code above wasn't within a form element, that could have caused the issue.
That was the issue in my case, after placing the radio elements within the form, the checked attribute worked again as expected. Hopefully this helps someone else out as well.

Related

How to show checkbox selected in edit page if user select the checkbox on submit

I have a check box simple form with two fileds, on submit I am submitting the values yes or no in the database, now in edit I want to show that checkbox selected.
<div class="form-group col-md-6">
<label> Is Paid</label></br>
Yes <input type="checkbox"
name="paid"
value="yes"
value=" <?php echo $row_cat['is_paid']; ?>"
/>
No <input type='checkbox' name="paid" value="no" />
</div>
How can I show prefilled checkbox on edit page ?
Try
<div class="form-group col-md-6">
<label> Is Paid</label></br>
Yes <input type="checkbox"
name="paid"
value="yes"
<?php echo $row_cat['is_paid']=='yes'?' checked="checked" ':''; ?>
/>
No <input type='checkbox'
name="paid"
value="no"
<?php echo $row_cat['is_paid']=='no'?' checked="checked" ':''; ?>
/>
</div>

PHP - Getting Multiple Radio Buttons Values from From Submission

I am a newbie in PHP. I have a form like below:
<div class="col-xs-2 col-xs-offset-1">
<input id="radio-ge-1" class="radio-custom" name="radio-ge" type="radio" value="1" checked>
<label for="radio-ge-1" class="radio-custom-label tooltips">1 <span>Impossible to get marks</span></label>
</div>
<div class="col-xs-2">
<input id="radio-ge-2" class="radio-custom" name="radio-ge" value="2" type="radio">
<label for="radio-ge-2" class="radio-custom-label tooltips">2 <span>You have to work hard to get marks</span></label>
</div>
<div class="col-xs-2">
<input id="radio-ge-3" class="radio-custom" name="radio-ge" value="3" type="radio">
<label for="radio-ge-3" class="radio-custom-label tooltips">3 <span>The usual, just like any other class</span></label>
</div>
<div class="col-xs-2 col-xs-offset-1">
<input id="radio-sl-1" class="radio-custom" name="radio-sl" value="1" type="radio" checked>
<label for="radio-sl-1" class="radio-custom-label tooltips">1 <span>Unbearable pressure</span></label>
</div>
<div class="col-xs-2">
<input id="radio-sl-2" class="radio-custom" name="radio-sl" value="2" type="radio">
<label for="radio-sl-2" class="radio-custom-label tooltips">2 <span>High pressure, But doable</span></label>
</div>
<div class="col-xs-2">
<input id="radio-sl-3" class="radio-custom" name="radio-sl" value="3" type="radio">
<label for="radio-sl-3" class="radio-custom-label tooltips">3 <span>Fair, just like any other class</span></label>
</div>
I'm trying to save both radio buttons value in PHP by using the code:
$g_Easiness = $_POST['radio-ge'];
$s_Load = $_POST['radio-sl'];
But in this case, I'me only getting the first button's value. Second button's value = on.
I have spend more than two hours to figure it out. But cannot resolve it. Can anyone please help me to solve the problem?
Please use below code for radio buttons
if input type="radio" then it should give value="" otherwise in value it will show "on"
e.g.
<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked>
output = [radio-nns] => on
instead put ( you can see value="1")
<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked value="1">
output = [radio-nns] =>1

radio button "Checked" option not working

Could you please help me why my checked option in the following code is not working?
<div class="span1">
<h7> Sex</h7>
<label class="radio">
<input id="pccf_sexMF" name="pccf_sexMF" value="M" type="radio" checked class="span1" > M
</label>
<label class="radio">
<input id="sexMF" name="pccf_sexMF" value="F" type="radio" class="span1"> F
</label>
</div>
Thanks
It works on this fiddle
<div class="span1">
Sex
<label class="radio">M</label>
<input id="pccf_sexMF" name="pccf_sexMF" value="M" type="radio" checked="checked" class="span1"/>
<label class="radio">F</label>
<input id="sexMF" name="pccf_sexMF" value="F" type="radio" class="span1"/>
</div>
First - no such thing as h7
Only text should be in a label, not the input
As I said in my comment, you could have another element with position:absolute that will cover your div because its height is bigger than you need it to be. Something like this:
http://jsfiddle.net/hescano/8T7Nc/
To avoid this, you can set your div a relative position:
<div class="span1" style="position:relative">
http://jsfiddle.net/hescano/8T7Nc/1/

Can I check a checkbox outside of an HTML input tag?

I am writing a php site that has a form with a series of check boxes. I will be loading an array from a file that I would like to go through and check some of the boxes by default when the form is loaded.
Here is an example:
<form action="mypage.php">
<label for="option1">Option 1</label>
<input type="checkbox" name="option1" value="option1" />
<label for="option2">Option 2</label>
<input type="checkbox" name="option2" value="option2" />
<label for="option3">Option 3</label>
<input type="checkbox" name="option3" value="option3" />
</form>
<?php
$array = array("option1", "option3");
// for loop to check boxes 1 and 3.
?>
Is this possible? What would be the best way to do it.
You should fill your array before the HTML part. And then:
<input type="checkbox" name="option1" value="option1" <?php if (in_array("option1", $array)) { echo 'checked="checked"'; } />
Try this :
<?php
$array = array("option1", "option3");
// for loop to check boxes 1 and 3.
?>
<form action="mypage.php">
<label for="option1">Option 1</label>
<input type="checkbox" name="option1" value="option1" <?php if(in_array("option1",$array)){?> checked="checked"<?php}?> />
<label for="option2">Option 2</label>
<input type="checkbox" name="option2" value="option2" <?php if(in_array("option2",$array)){?> checked="checked"<?php}?> />
<label for="option3">Option 3</label>
<input type="checkbox" name="option3" value="option3" <?php if(in_array("option3",$array)){?> checked="checked"<?php}?> />
</form>

html5 form not reacting to submit

I've got a simple one-page form, the kind I've written dozens of times, but this behavior is totally new to me. At first, it was submitting on page-load, thus redirecting automatically to the next page in the series. I'm still not sure how I got that to stop, but now it's not doing anything at all when you hit "submit". The page simply sits there.
I've tried stripping out the error-checking scripts, the show/hide script, even jquery itself, then taking the form down to just one input. I tried getting rid of the redirect and just having it output a simple line, then vardump, and still nothing. I hit submit, and no matter what I do, the page just sits there. I've never run into behavior like this before, and firebug et al give me no errors or leads.
If anyone has any ideas at all, no matter how crazy, I'm willing to try. I'm at a loss. Thanks in advance!
<?php
session_start();
include('functions.php');
if ($_POST['submit']) {
$company = $_POST['company'];
$taxid = $_POST['taxid'];
header("location:step2.php");
}
include('head.php'); ?>
<form method="post" name="basic" action="step1.php">
<div class="col70">
<label for="company">Organization/Business name <img src="img/req.jpg" alt="required"></label>
<input type="text" name="company" id="company" value="" />
</div>
<div class="col30">
<label for="taxid">Taxpayer ID# (IEN or SS#) <img src="img/req.jpg" alt="required"></label>
<input type="text" name="taxid" id="taxid" value="" />
</div>
<div class="newcol">
<label for="address">Mailing Address <img src="img/req.jpg" alt="required"></label>
<input type="text" name="address" id="address" value="" />
</div>
<div class="col30 newcol">
<label for="city">City <img src="img/req.jpg" alt="required"></label>
<input type="text" name="city" id="city" value="" />
</div>
<div class="col30">
<label for="state">State <img src="img/req.jpg" alt="required"></label>
<select name="state" id="state" tabindex="<?php echo $tabin; $tabin++; ?>">
<option value="0"></option>
<option value="1">Alabama</option>
</select>
</div>
<div class="col25">
<label for="zipcode">Zip Code <img src="img/req.jpg" alt="required"></label>
<input type="text" name="zipcode" id="zipcode" value="" />
</div>
<fieldset><legend>1. What kind of group/company do you have? <img src="img/req.jpg" alt="required"></legend>
<span id="nfpfp" class="InputGroup">
<label><input name="nfpfp" id="nfpfp_1" type="radio" value="1" />For-profit business.</label>
<label><input name="nfpfp" id="nfpfp_2" type="radio" value="2" />Non-profit 501(c)3 organization.</label>
</span>
</fieldset>
<fieldset><legend>2. How will you use the booth space? Select all that apply. <img src="img/req.jpg" alt="required"></legend>
<span id="type" class="InputGroup">
<label><input name="food" id="type_1" type="checkbox" value="1" />Food sales</label>
<label><input name="retail" id="type_2" type="checkbox" value="2" />Retail sales</label>
<label><input name="activity" id="type_3" type="checkbox" value="3" />Activity</label>
<label><input name="display" id="type_4" type="checkbox" value="4" />Display</label>
<label><input name="other" id="type_5" type="checkbox" value="5" />Other</label>
</span>
</fieldset>
<label for="otherdetails" class="newcol offsides">Enter a short description of your use. (Ex: "BBQ sandwiches", "kite kits", "face painting".) <img src="img/req.jpg" alt="required"></label>
<input type="text" name="otherdetails" id="otherdetails" value="" />
<fieldset><legend>3. Select any/all that apply. Additional questions may appear, if further information is required.</legend>
<span id="additional" class="InputGroup">
<label><input name="raffle" id="raffle_1" type="checkbox" class="switchcheck1" value="1" />I'll be selling raffle tickets and/or holding a raffle at the festival.</label>
<div class="newcol offstate1">
<label for="raffledetails">You'll need written permission from the Exchange Club. Please enter details about the raffle. <img src="img/req.jpg" alt="required"></label>
<textarea name="raffledetails" id="raffledetails" tabindex="<?php echo $tabin; $tabin++; ?>"></textarea>
</div>
<label><input name="trailer" type="checkbox" id="trailer_1" value="1">I'll be bringing a trailer.</label>
<label><input name="outlets" type="checkbox" id="outlets_1" class="switchcheck2" value="1" />I'll require electrical outlets.</label>
<div class="newcol offstate2">
<label for="outletsdetails">How many outlets will you require? <img src="img/req.jpg" alt="required"></label>
<input type="text" name="outletsdetails" id="outletsdetails" />
</div>
</span>
</fieldset>
<input type="button" name="submit" class="a_button" value="submit" />
</form>
The element with name="submit" is of type button and not submit, so it renders a plain button that does nothing (with the intention that you bind some JavaScript to it).
Use type="submit" instead.
Try
<input type="submit" name="submit" class="a_button" value="submit" />
for your submit button.

Categories