Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Free host forum is not reliable
- Using Cron Job to process PHP scripts
- job interview questions (1)
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- PHP connect IBM db2 database in XAMPP
- Set up a child account and set screen time limit in Windows 8
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHPMailer 5.2.4 and use smtp gmail
Friday, March 8, 2013
PHP form submission with check box, radio button and dropdown menu
1. For PHP checkbox form submission, we still can only need one column in MySQL using PHP bitwise function &. (note we can have multi-choice in checkbox). Example code :
<input type="checkbox" name="competency[]" value="4" <?php if(($row['competency']&4) == 4){ echo('checked="checked"'); } ?> /> Hard skill
<input type="checkbox" name="competency[]" value="2" <?php if(($row['competency']&2) == 2){ echo('checked="checked"'); } ?> /> Soft skill
<input type="checkbox" name="competency[]" value="1" <?php if(($row['competency']&1) == 1){ echo('checked="checked"'); } ?> /> Others
In the action side:
$comp =0;
foreach($_POST['competency'] as $pc) {
$comp = $comp + intval($pc);
}
and insert $comp in database as column competency, which will be used in $row['competency']
2. For dropdown menu:
<select name="competency" id="competency">
<option value="">- select -</option>
<option value="3" <?php if($row['competency'] == 3){ echo('selected="selected"'); } ?> > Hard skill </option>
<option value="2" <?php if($row['competency'] == 2){ echo('selected="selected"'); } ?> > Soft skill </option>
<option value="1" <?php if($row['competency'] == 1){ echo('selected="selected"'); } ?> > Others </option>
</select>
In the action side:, we can insert $_POST['competency'] as it is a unique value.
3. For radio button:
<input type="radio" id="c1" class="input-radio" name="competency" value="3" <?php if($row['competency'] == 3){ echo('checked="checked"'); } ?> />
<label for="c1">Yes, with hard skill</label>
<input type="radio" id="c2" class="input-radio" name="competency" value="2" <?php if($row['competency'] == 2){ echo('checked="checked"'); } ?> />
<label for="c2">Yes, with soft skill</label>
<input type="radio" id="c3" class="input-radio" name="competency" value="1" <?php if($row['competency'] == 1){ echo('checked="checked"'); } ?> />
<label for="c3">No</label> <br />
In the action side:, we can insert $_POST['competency'] as it is a unique value.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment