Mathematical expressions on html/php checkboxes - php

I have a table in html which lists review entries then scores them using a drop down box. I am wondering how to count the results:
<td class="views-field views-field-field-price-editable" >
<div class="views-row-edit-static"></div><div class="views-row-edit-edit"><div class="field-type-list-text field-name-field-price field-widget-options-buttons form-wrapper" id="edit-node-59200313-field-price"><div class="form-item form-type-radios form-item-node-59200313-field-price-und">
<label for="edit-node-59200313-field-price-und">Price <span class="form-required" title="This field is required.">*</span></label>
<div id="edit-node-59200313-field-price-und" class="form-radios"><div class="form-item form-type-radio form-item-node-59200313-field-price-und">
<input type="radio" id="edit-node-59200313-field-price-und-no-mention" name="node[59200313][field_price][und]" value="no mention" checked="checked" class="form-radio" /> <label class="option" for="edit-node-59200313-field-price-und-no-mention">No Mention </label>
</div>
<div class="form-item form-type-radio form-item-node-59200313-field-price-und">
<input type="radio" id="edit-node-59200313-field-price-und-positive" name="node[59200313][field_price][und]" value="positive" class="form-radio" /> <label class="option" for="edit-node-59200313-field-price-und-positive">Positive </label>
</div>
<div class="form-item form-type-radio form-item-node-59200313-field-price-und">
<input type="radio" id="edit-node-59200313-field-price-und-negative" name="node[59200313][field_price][und]" value="negative" class="form-radio" /> <label class="option" for="edit-node-59200313-field-price-und-negative">Negative </label>
</div>
</div>
</div>
</div></div> </td>
There are 3 options: 1) "No Mention" 2) Positive 3) Negative
In the code, the field 'Service' has been scored 'positive'.
How do I count these values up, so I can see how many 'Positives' there are in my 'Service' column? The website is run on php so I'd assume I can use this but as the fields are not numeric I am not so sure. Any help appreciated.

You have to provide us with more (HTML) code (the part with No Mention and Negative) for us to help you out but you (probably) only need to create a new variable and set it to zero and every time a field has the value Positive you just add one to the variable - but without the HTML and PHP code we cannot really help you more!

Related

Add Multiple Choice Questions to PHP Web Form

I have a standard PHP web form with text fields, dropdowns, and radio buttons. When the form is submitted, the submitted information is e-mailed to me. I want to add a multiple choice question with checkboxes. I can produce the form field, but I can't figure out how to include multiple selections for that one question on the e-mail that gets sent when the form is submitted. Ideally, I would like to have the multiple selections on one line and separated by semi-colons (or commas if that's easier)
I've included what I think are the relevant parts of the code. Apologies if I didn't format this post correctly.
<form action="example.php" method="post" autocomplete="off">
<div class="form-row">
<label for="first">
<span>First Name:</span>
<input type="text" id="first" name="first" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row">
<label for="last">
<span>Last Name:</span>
<input type="text" id="last" name="last" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row">
<label for="email">
<span>E-mail:</span>
<input type="text" id="email" name="email" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row-multiple">
<label for="multiple">
<span>Choose all that apply:</span><br>
<input type="checkbox" name="multiple" id="multiple" value="Option 1"><span>Option 1</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 2"><span>Option 2</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 3"><span>Option 3</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 4"><span>Option 4</span> </label>
</div>
<div class="form-row">
<button type="submit" name="submit" id="submit"><b>Submit</b></button>
</div>
</form>
<?php
$first = remove_headers($_POST['first']);
$last = remove_headers($_POST['last']);
$email = remove_headers($_POST['email']);
$multiple = remove_headers($_POST['multiple']);
$message =
"First: $first\n\n" .
"Last: $last\n\n"
"E-mail: $email\n\n"
"Multiple: $multiple\n\n"
Two things to do here,
For multiple checkboxes use the name attribute as an array and remove the id attribute, as an HTML page should have a unique ID throughout.
<input type="checkbox" name="multiple[]" value="Option 1"><span>Option 1</span>
<input type="checkbox" name="multiple[]" value="Option 2"><span>Option 2</span>
<input type="checkbox" name="multiple[]" value="Option 3"><span>Option 3</span>
<input type="checkbox" name="multiple[]" value="Option 4"><span>Option 4</span>
When the form is submitted, multi-valued checkboxes are received as an array. So, we can make it semicolon-separated using the implode() function.
$multiple = implode(';', $_POST['multiple']);

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/

Text for checkboxes not appearing in Drupal 6

This is a Drupal 6 build, I'm trying to figure out why the checkboxes are not showing text. Here's an image of what's going on - you can see that the checkboxes are empty.
The actual generated code is as follows:
<div id="attach-wrapper"><div id="edit-files-392-description-wrapper" class="form-item">
<input type="text" class="form-text" value="2011 SchoolAgePQA_Sample_Items.pdf" size="60" id="edit-files-392-description" name="files[392][description]" maxlength="256">
<div class="description"><small>http://domain.org/sites/domain.org/files/2011 SchoolAgePQA_Sample_Items.pdf</small></div>
</div>
492.94 KB<div id="edit-files-392-remove-wrapper" class="form-item">
<input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-remove" name="files[392][remove]">
</div>
<div id="edit-files-392-list-wrapper" class="form-item">
<input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-list" name="cats">
</div>
<div id="edit-files-392-weight-wrapper" class="form-item">
<select id="edit-files-392-weight" class="form-select" name="files[392][weight]"><option value="-8">-8</option><option value="-7">-7</option><option value="-6">-6</option><option value="-5">-5</option><option value="-4">-4</option><option value="-3">-3</option><option value="-2">-2</option><option value="-1">-1</option><option selected="selected" value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option></select>
</div>
<div id="edit-files-392-private-wrapper" class="form-item">
<input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-private" name="files[392][private]">
</div>
The only thing that sticks out to me is that the value of the checkboxes is exactly the same as the name - and those are all various positive and negative integers.
I've never seen this before, and I'm not sure what might cause it - incorrect configuration setting, poorly coded theme, something else?
There's no label there, so no text is going to be displayed. In drupal it should allow you to change the label and set a value.
The output code should look similar to
<label><input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-list" name="cats">Cats</label>
Try to add label or simply text after your checkbox:
<div id="edit-files-392-list-wrapper" class="form-item">
<label> Text here
<input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-list" name="cats">
</label>
</div>
Or simply :
<div id="edit-files-392-list-wrapper" class="form-item">
<input type="checkbox" class="form-checkbox" value="1" id="edit-files-392-list" name="cats">
Text here
</div>
But i recommande the first solution.

Not returning selected pciture name

I have a database with pictures that i can delete from or use them in different parts of the the website by choosing one of the radio buttons in the popup.Problem is everytime I click I click on a picture the name of the first picture in the database comes up not the one from the picture i clicked . What's wrong? I used PHP 5.3 and HeidiSQL
<?php
// ...
$result=mysql_query("SELECT * FROM imagini WHERE menu_id=6");
while($data=mysql_fetch_row($result)){ ?>
<div class="tag">
<div id='container_poze_originale'>
Alege alt rol
<div id="my_popup" style="display:none;border:1px dotted gray;padding:.3em;background-color:white;position:absolute;width:auto;left:100px;top:100px">
close
<form action="popup.php" method="post" >
<input type="text" name="alt-rol" value="<?php echo $data[1];?>" /> //always returns the name of the first picture in the database not the one i select
<input type="submit" value="Adauga imagine" class="buton_imagine" />
<div class="radio">
<input type="radio" name="tip_imagine" value="0"/><label for="tip_imagine" class="radio2">Logo</label>
<input type="radio" name="tip_imagine" value="1"/><label for="tip_imagine" class="radio2">Slider</label>
<input type="radio" name="tip_imagine" value="2"/><label for="tip_imagine" class="radio2">Hot destinations</label>
<input type="radio" name="tip_imagine" value="3"/><label for="tip_imagine" class="radio2">Pachete</label>
<input type="radio" name="tip_imagine" value="4"/><label for="tip_imagine" class="radio2">Reclama</label>
<input type="radio" name="tip_imagine" value="5"/><label for="tip_imagine" class="radio2">Background</label>
</div>
</form>
</div>
<div class="imagine_originala">
<img src= "../upload/original/<?php echo $data[1];?>" /></a>
</div>
<div class="Btag" style="display:none;">
<div id="buton_slide4" >
Sterge</td>
</div>
</div>
</div>
</div>
<?php
}
?>
I think I understand your question. You are clicking on
Alege alt rol
and you are surprised that the same <div> always appears?
Well, it is simply because an id should be unique. And if you cycle through your images you create a new <div> each time with the same id: my_popup. When clicking on the link (no matter which one), JavaScript will then just take the first <div> it finds with the id my_popup. So you should just assign an unique id to each div so your JavaScript knows which one to open. You could do this by appending your image id to the div id (assuming you have a unique image id in $data[1]).
So change it to (shortened):
<? while($data=mysql_fetch_row($result)) { ?>
<div class="tag">
<div id="container_poze_originale">
Alege alt rol
<div id="my_popup<?=$data[1]?>" style="display:none;border:1px dotted gray;padding:.3em;background-color:white;position:absolute;width:auto;left:100px;top:100px">
...
</div>
</div>
</div>
<? } ?>
Oh and it might be good to put all those huge inline CSS attributes into an external stylesheet, so it will be easier to maintain/change your webpage later on. And it makes things a bit more readable... :-)
I think your form is ok when you click on the radio but not when you click on the label.
The for attribute of the label need an ID as reference like this :
<input type="radio" name="tip_imagine" value="0" id="tip0" /><label for="tip0" class="radio2">Logo</label>
<input type="radio" name="tip_imagine" value="1" id="tip1"/><label for="tip1" class="radio2">Slider</label>
<input type="radio" name="tip_imagine" value="2" id="tip2"/><label for="tip2" class="radio2">Hot destinations</label>
<input type="radio" name="tip_imagine" value="3" id="tip3"/><label for="tip3" class="radio2">Pachete</label>
<input type="radio" name="tip_imagine" value="4" id="tip4"/><label for="tip4" class="radio2">Reclama</label>
<input type="radio" name="tip_imagine" value="5" id="tip5"/><label for="tip5" class="radio2">Background</label>
With your actual code, the FOR is always the same so you get always the first.

Categories