I tried to search yet i unable to find out what i am looking for.Please help me.I am working on a rating form which using radio button star for rating,I am using while loop of mysqli_fetch_assoc to pull the date from database.As shown below
<?php
$sql = "SELECT * FROM orderdetail,orderuser,food WHERE orderuser.CustomerID=orderdetail.CustomerID AND orderuser.OrderID=orderdetail.OrderID AND orderdetail.FoodID=food.FoodID AND orderuser.confirmstatus=1";
$result = $conn->query($sql) or die($conn->error);
while($colum = mysqli_fetch_assoc($result))
{
?>
<img src="../php/<?php echo $colum['Foodphoto'];?>" style="height:150px;width:150px">
<br>
<?php echo $colum['FoodName'];?>
<br>
<div class="stars">
<form action="">
<input class="star star-5" id="rate-5[]" type="radio" name="rate[]" />
<label class="star star-5" for="rate-5[]"></label>
<input class="star star-4" id="rate-4[]" type="radio" name="rate[]" />
<label class="star star-4" for="rate-4[]"></label>
<input class="star star-3" id="rate-3[]" type="radio" name="rate[]" />
<label class="star star-3" for="rate-3[]"></label>
<input class="star star-2" id="rate-2[]" type="radio" name="rate[]" />
<label class="star star-2" for="rate-2[]"></label>
<input class="star star-1" id="rate-1[]" type="radio" name="rate[]" />
<label class="star star-1" for="rate-1[]"></label>
</form>
</div>
<hr>
<?php
}
?>
but the rating for the second result is not working,i find out that is due to the problem of name but i tried to edit it by adding the array still not working. And how could i store them into mysql using php?those tutorial i found only using ajax or jquery i need the ratings submit once the user submitted the form.
The problem I think is that you cannot relate the form being submitted with the record so any update will not work as expected. One of the simplest ways to accomplis this would be a hidden field with the ID of the record - the ID can then be used in the update statement - ie: ( pseudo sql update )
update orderdetail set rating=$rate where ID=$id
So, add a hidden field per form like this perhaps
while($colum = mysqli_fetch_assoc($result)){
?>
<img src='../php/<?php echo $colum['Foodphoto'];?>' style='height:150px;width:150px'>
<br>
<?php echo $colum['FoodName'];?>
<br>
<div class='stars'>
<form action=''>
<input class='star star-5' type='radio' id='rate-5' name='rate' />
<label class='star star-5' for='rate-5'></label>
<input class='star star-4' type='radio' id='rate-4' name='rate' />
<label class='star star-4' for='rate-4'></label>
<input class='star star-3' type='radio' id='rate-3' name='rate' />
<label class='star star-3' for='rate-3'></label>
<input class='star star-2' type='radio' id='rate-2' name='rate' />
<label class='star star-2' for='rate-2'></label>
<input class='star star-1' type='radio' id='rate-1' name='rate' />
<label class='star star-1' for='rate-1'></label>
<!--
HIDDEN FIELD WITH ID
-->
<input type='hidden' name='id' value='<?php echo $colum['id'];?>' />
</form>
</div>
<hr>
Related
I made radio buttons and all radio buttons are selected, where I try my code.
How to choose just one radio button in sintaks laravel?
This is My View Page :
<div class="form-group">
<b>Paket</b>
<br/>
<fieldset>
<input type="checkbox" name="delux" id="delux" value="d"> <label for="">Paket Delux </label>
<input type="checkbox" name="paket1" id="p1" value="p1"> <label for="">Paket 1</label>
<input type="checkbox" name="paket2" id="p2" value="p2"> <label for="">Paket 2</label>
</fieldset>
</div>
<div class="form-group">
<b>Jenis Pembayaran</b>
<br/>
<fieldset>
<form id="form_radio" name="form_radio">
<input type="radio" value="tunai" name="tunai" id="rd1"> <label for="">tunai</label>
<br>
<input type="radio" value="non" name="nontunai" id="rd2"> <label for="">non tunai</label>
</fieldset>
</div>
<input type="submit" value="Upload" class="btn btn-primary">
</form>
And this is My controller :
public function input()
{
$jenis = JenisMkn::select('id_jenis','jenis_makanan')->get();
return view('upload_gambar',['jenis'=>$jenis]);
}
public function proses(Request $request)
{
$cek = Gambar::get('checkbox');
echo $cek;
$radio = Gambar::get('radio');
echo $radio;
What the fault in my code?
Any help? Thank you.
Simply give them the same name, cek this code:
<input type="radio" value="tunai" name="transaksi" id="rd1"> <label for="">tunai</label>
<br>
<input type="radio" value="non" name="transaksi" id="rd2"> <label for="">non tunai</label>
You can rename the name input with your name.
If you want only one radio button to get selected then you must specify same value for name property. for example:
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Hope it helped.
This is a 5-star rating form and I am trying to make it work.
<div class="stars">
<form>
<input class="star star-5" id="star-5" type="radio" name="star" value="5"/>
<label class="star star-5" for="star-5"></label>
<input class="star star-4" id="star-4" type="radio" name="star" value="4"/>
<label class="star star-4" for="star-4"></label>
<input class="star star-3" id="star-3" type="radio" name="star" value="3"/>
<label class="star star-3" for="star-3"></label>
<input class="star star-2" id="star-2" type="radio" name="star" value="2"/>
<label class="star star-2" for="star-2"></label>
<input class="star star-1" id="star-1" type="radio" name="star" value="1"/>
<label class="star star-1" for="star-1"></label>
<button class="button" type="submit" name="submit" value="submit">Submit</button>
</form>
</div>
When I press the submit button nothing happens. The code does not move into the if statement, though it should since submit is not longer null.
<?php
if(isset($_POST['submit'])){
$rating = $_POST['star'];
echo "hello";
echo $rating;
}
?>
set form method=post
if html and php code in same page use
set form action="" otherwise use
set form action=".php file"
for ex:<form method="post" action=" or .php file">
You just missed to put form method and action in form.
Use this
<form method="post" action="" >
and on php code use
if(isset($_POST['star']))
it will work
To use super global variable $_POST, u need to specify method attribute to the form tag with submit button.
Change your form tag and your submit button tag to :
<div class="stars">
<form method="POST" name="starRatingForm" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input class="star star-5" id="star-5" type="radio" name="star" value="5"/>
<label class="star star-5" for="star-5"></label>
<input class="star star-4" id="star-4" type="radio" name="star" value="4"/>
<label class="star star-4" for="star-4"></label>
<input class="star star-3" id="star-3" type="radio" name="star" value="3"/>
<label class="star star-3" for="star-3"></label>
<input class="star star-2" id="star-2" type="radio" name="star" value="2"/>
<label class="star star-2" for="star-2"></label>
<input class="star star-1" id="star-1" type="radio" name="star" value="1"/>
<label class="star star-1" for="star-1"></label>
<input type="submit" name="submit" value="submit"/>
</form>
</div>
isset() checks if a variable has a value including ( False , 0 , or empty string) , but not NULL. Returns TRUE if variable exists otherwise returns FALSE.
On the other hand the empty() function checks if the variable has an empty value, empty string , 0, NULL ,or False. Returns FALSE if variable has a non-empty and non-zero value.
Example
if(!empty($_POST['star'])){
....
}
You have to set method and action attributes in the form tag.
<form method='post' action='page.php'>
Is it possible to have a : separator in a form input field for a manual time input? Something like the following example:
<p>
<div class='field'>
<label for='$time_in'>Time In</label>
<input type='text' name='time_in' id='time_in'
size='10' maxlength='5' /></div>
</p>
Using "Internet explorer"
You can take 2 seperate fields like
<p>
<div class='field'>
<label for='$time_in'>Time In</label>
<input type='text' name='time_in1' id='time_in1'
size='10' maxlength='2' />
:
<input type='text' name='time_in2' id='time_in2'
size='10' maxlength='2' />
</div>
</p>
and handle them separately in the code, it will work!
The code below is a dynamic way of displaying each option as checkbox buttons for each question:
function ExpandOptionType($option) {
$options = explode('-', $option);
if(count($options) > 1) {
$start = array_shift($options);
$end = array_shift($options);
do {
$options[] = $start;
}while(++$start <= $end);
}
else{
$options = explode(' or ', $option);
}
echo '<p>';
foreach($options as $indivOption) {
echo '<div id="ck-button"><label class="fixedLabelCheckbox"><input type="checkbox" name="options[]" id="option-' . $indivOption . '" value="' . $indivOption . '" /><span>' . $indivOption . '</span></label></div>';
}
echo '</p>';
}
foreach ($arrQuestionId as $key=>$question) {
?>
<p><?php echo ExpandOptionType(htmlspecialchars($arrOptionType[$key])); ?></p>
<p><input type='text' class='questionIds' name='questionids' value='<?php echo htmlspecialchars($arrQuestionId[$key]); ?>' /></p>
<p><input type='text' class='responseTime' name='responsetime' value='00:00:00' /></p>
<p><input type='text' class='mouseClick' name='mouseclick' value='0' /></p>
}
Now below I 2 text inputs which are also in the foreach loop, one for response time and other is for counting mouse click:
<p><input type='text' class='responseTime' name='responsetime' value='00:00:00' /></p>
<p><input type='text' class='mouseClick' name='mouseclick' value='0' /></p>
Now this is my questions:
The response time text input contains a count up timer. What I want is that if the first button checkbox is clicked in a question, the question's response timer should stop. This is so we know how long it took the user to respond answering a particular question
The mouse click text starts with 0 and what I want this text input to do is for every button checkbox that is clicked in a question, the question's mouse click text input counts up the amount of clicks so we know how many clicks on the question's options the user has compiled.
How can the above be achieved?
Below is a jsfiddle showing sample code of what it looks like for one question:
http://jsfiddle.net/zAFND/630/
UPDATE:
Source code showing multiple questions example:
QUESTION 1:
<p>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-A" value="A" />
<span>A</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-B" value="B" />
<span>B</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-C" value="C" />
<span>C</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-D" value="D" />
<span>D</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-E" value="E" />
<span>E</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-F" value="F" />
<span>F</span>
</label>
</div>
</p>
<p><input type='text' class='questionIds' name='questionids' value='73' /></p>
<p><input type='text' class='responseTime' name='responsetime' value='00:00:00' /></p>
<p><input type='text' class='mouseClick' name='mouseclick' value='0' /></p>
QUESTION 2:
<p>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-A" value="A" />
<span>A</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-B" value="B" />
<span>B</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-C" value="C" />
<span>C</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-D" value="D" />
<span>D</span>
</label>
</div>
<div id="ck-button">
<label class="fixedLabelCheckbox">
<input type="checkbox" name="options[]" id="option-E" value="E" />
<span>E</span>
</label>
</div>
</p>
<p><input type='text' class='questionIds' name='questionids' value='74' /></p>
<p><input type='text' class='responseTime' name='responsetime' value='00:00:00' /></p>
<p><input type='text' class='mouseClick' name='mouseclick' value='0' /></p>
As you created a reference for setinterval that is good. Now you can remove the set interval on click event of first checkbox and add a click event on all checkbox to increase counter.
That will be
$(document).ready(function(){
var checkBox=$('#ck-button').find('input');
var responsetimer=//your interval function
checkbox.filter(':first').bind('click',function(e){
clearInterval(responsetimer);
});
checkbox.bind('click',function(e){
$('.mouseClick').val(parseInt($('.mouseClick').val())+1);
});
});
Well i am not sure about the question you want timer to be stopped at first button click or first time button clicked. If it is first time than dont use the first binding . keep clear interval in second binding itself.
checkbox.bind('click',function(e){
clearInterval(responsetimer);
$('.mouseClick').val(parseInt($('.mouseClick').val())+1);
});
JS fiddle :http://jsfiddle.net/zAFND/631/
for second option
http://jsfiddle.net/zAFND/638/
UPDATE
if you want this for multiple question wrap each question with a div say <div class="queWrap"></div>
Make a array refrence for your interval function so that it can be clear.
Loop to each queWrap and start timer and assign events on checkbox.
Check example for multiple question :http://jsfiddle.net/zAFND/640/
how can i get multiple value data from multi checkbox options? Following are my checkbox html code that can select multiple values
<li class='voteable-attribute off clearfix'>
<label class='primary formField'>Parking:
</label>
<div class='inputFields ieSucks'>
<div class='thereisonlybool'>
<label for='av_box:BusinessParking:valet'>
<input type='checkbox' id='av_box:BusinessParking:valet' name='BusinessParking_valet' value='1'>
Valet
</label>
</div>
<div class='thereisonlybool'>
<label for='av_box:BusinessParking:garage'>
<input type='checkbox' id='av_box:BusinessParking:garage' name='BusinessParking_garage' value='1'>
Garage
</label>
</div>
<div class='thereisonlybool'>
<label for='av_box:BusinessParking:street'>
<input type='checkbox' id='av_box:BusinessParking:street' name='BusinessParking_street' value='1'>
Street
</label>
</div>
<div class='thereisonlybool'>
<label for='av_box:BusinessParking:lot'>
<input type='checkbox' id='av_box:BusinessParking:lot' name='BusinessParking_lot' value='1'>
Private Lot
</label>
</div>
<div class='thereisonlybool'>
<label for='av_box:BusinessParking:validated'>
<input type='checkbox' id='av_box:BusinessParking:validated' name='BusinessParking_validated' value='1'>
Validated
</label>
</div>
</div>
</li>
From zend controller i can access single value as follow:
$data1 = $this->_getParam('input_name')
But in this case there is multiple value, how can i get this multiple values in zend controller and store it on array and save on db.Thanks
You have to create a element with this name BusinessParking[].
meand create this checkbox like array.
now when you get value controller then you get what you want.
Create the html page as:
<input type="hidden" name="id[]" value="<?php echo $value[i] ?>"/>
Note the name="id[]", that's the trick. Now in Zend you can get the values as:
$array = $this->getRequest()->getParam("id");