Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Checkbox Onchange To Add Value To Array?


I want to have a couple checkbox inputs that when 'onchage' add the value of the checkbox to an array, that will be assigned to a variable. Is this possible?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Checkbox Array
checkbox arrays do not hold their respective positions as do other field arrays that are established to store the contents of selected records. The problem is that when you "uncheck" one of the elements and then repost, that array element disappears and the whole array collapses and renumbers itself with only the remaining "checked" ones -- simply useless when dealing with records in a table where all the field array elements should be in sync.

I consider it a bug -- why does the array have to collapse? Why can't it just hold a null value and keep its position? The only fix is to never hold checkbox values in an array. Store them in individual variables numbered like an array, then do an "eval" to retrieve the contents. Here's the whole thing in action: Code:

Checkbox Array
I have a list of checkboxes. The name for each is being pulled up from a database. Each (minus irrelevent or implicit code) looks like this ...

<input type=checkbox name=assnid$assnarray[assnid] value=1>

or...peaking at the HTML, the list looks like this:

<input type=checkbox name=assnid1 value=1>
<input type=checkbox name=assnid2 value=1>
<input type=checkbox name=assnid3 value=1>

and so on...
Anybody know how to post the selected checkboxes into $assnidarray?
For example, assuming all are chosen, $assnidarray would be (1,2,3,...).

Checkbox Array
I have a checkbox array containing the id of a record in a MySQL database.
The checkboxes are created dynamically depending on what is stored in the
database. I want to send the checkbox array to my stop_subscriptions.php
file, running the code on all checked boxes, however I dont seem to be able
to actually send the array, I was hoping that someone could steer me in the
right direction.

<?php
$sql = "SELECT i.type, i.title , s.inj_id FROM inj_subscription s,
injustices i WHERE s.member_id = '$user' AND i.inj_id = s.inj_id AND
s.inj_id IS NOT null" ;
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result) ;
if ($row) {
echo "<div><span>Specific Subsriptions:</span><br/>" ;
$table_start ='<table width="90%" table name="table2" align="center"
cellspacing="0" border="0">
<tr>
<form method="post" action="stop_subscription.php">
<th width="20%">Type</th>
<th width="70%">Title</th>
<th width="10%"></th>
<input type="submit" name="Submit" value="Submit"
style="font-size:10px"/><p>
<input type="hidden" name="stop_subscription"
value="1"/>
</form>
</tr>'
echo $table_start;
$rownum = 0;
while($row) {
$rownum++;
$style = rowcolor($rownum);
$table_rows .= '<td id="td" align="center"
style="'.$style.'padding:5px;" >'."
".'<form><input type="checkbox"
name="deletethis[]" value="'.$row['inj_id'] . '"></form></td>'."
";
echo "<tr>" . $table_rows . "</tr>";
$row = mysql_fetch_assoc($result) ;
}
echo '</table><Br/></div><br/>'
}
?>

Checkbox Without Array
I have a question regarding implementing a checkbox that DOESN'T use arrays -- everything i find when i google has arrays in it!  So, I'm hoping someone here can help me come up with a solution to my problem.

I have a checkbox that a user can check (default will be to have it NOT checked) - and once it's checked, to keep it checked until the user unselects it again.

Here's my checkbox code:
<input type ="submit" name="cv_permission" type="checkbox">

What do I have to do to keep it turned 'ON' once it's checked?

Checking For Checkbox Array
I'm working on a page for an e-commerce site that has a form than lists items in an order placed by a customer. The form serves two purposes: to edit
and save the details of the items (i.e. number of items, price, etc.) and to split the order (i.e. select certain items to remove from the order and
use to create a new separate order). Each item has a checkbox next to it, and the name for the checkbox is "name[]" so an array of the checked items
is created and passed to the processing script. The logic I want to use to determine if the items are being saved or being split out is by looking at
the $name array. However, if I try something like "if ($_POST['name'])" and none of the checkboxes are checked, I get an Undefined Index error (it
works fine if there are items checked). What is a valid way to check to see if the $name array exists so I know which action to take?

Checkbox Array Problem
I have a form which contains several fields. One of which is a group of
checkboxes that can all be selected, and if they are - all values should be
passed as an array.

Each checkbox is Named as follows. myCheckBoxName[]

myCheckBoxName[]

I have the following code on the following page to pick up the results from
the querystring.

while(list($key, $value) = each($HTTP_POST_VARS))
{
$keys = $keys . "$key, ";
$values= $values . "'$value', ";
echo("$key = $value <br>" );
}

But the field which contains multiple checkboxes only displays the value
"array" - and nothing else.

Foreach On Checkbox Array
I am having a bit of an issue getting a foreach statement i have made to work , essentially what this for each statement is suposed to do is write a row to a database for each one of the check boxes selected here is the code:

Sticky Checkbox Array
I have a group of checkboxes that I would like to be sticky. I want the checkboxes that the user has checked to remain checked upon returning to the page from a validation error. Code:

Multi-dimensional Array For Checkbox
Can there be a multi-dimensional array for checkboxes?

HELP! Passing Checkbox Values To Array
I have a form with a repeating table display data from MySQL, ie, invoice numbers and invoice pricing.

I need to be able to select which invoices someone wants to pay via checkboxes. From here, I need to be able to display the corresponding records on another page where I can SUM() the invoice totals to give a price to be paid.

I've never used array's before but believe this is how it should be done. My brain is currently fried and I'm struggling...

How To Store Checkbox Values To An Array?
I need to allow the user to select multiple mysql records via an html form checkbox.  On submission of the form I would like to store these values in an array for either multiple record deletion or creating a list of records. Code:

Form Processor And Checkbox Array
I have been able to create simple forms on my html pages using a .php processor. For one I am working on now, I need to have two checkbox sections where the user can click multiple choices in each. It goes through my .php file and get's emailed. I need help with the code in the .php file on how to process two checkbox arrays and email the result. Code:

Problems With Dynamic Checkbox - Need To Create Array
The problem I have concerns a dynamically created table/form which pulls in results from a user search of a mysql database. This works fine and pulls in results (title/author/isbn/price) and dynamically creates the table dependent upon how many results are found. For each result there is a dynamically created checkbox, which is bound to a unique field from the database(in this case isbn).

My problem then is: the dynamically created checkbox submits an isbn value to the next page - an order form. However I need that a user can select a number of checkboxes from the table. At the moment, each selection overwrites the other. It may be vary obvious - but I need to work out some way of storing the checkbox info in an array that gets submitted to my order form page.

at the moment the code for my checkbox within the html form is:


<input name="isbn_input" type="checkbox" id="isbn_input" value="<?php echo $row_Rs_panozzo_search['isbn']; ?>" />
</font></td>

This works passing one value through to my order form, but I need to set it up so it passes multiple values.

Comparing PHP Array From Checkbox To MySQL Table
My problem involves updating a MySQL table using checkbox input. I'm relatively new to both PHP and MySQL so I'm looking for a little direction on the smartest way to accomplish my goal.

When a user goes to a project page, they are able to categorize their project by area. The user checks a series of checkboxes and the results are stored in an arrays called $category_ids. I'll called the project id $project_id.

What I want to do is compare the array $category_ids to entries in a MySQL table for $project_id. Then I want to add the links that aren't already in the table and delete the ones that need to be deleted. The table has these fields:

projects_cat_link (table)
----------------------
category_id ¦ project_id (fields)

Does anyone have any tips on how to do this? I've gathered that maybe there's a way to get the MySQL data into a similarly formed array and then use functions like array_diff to compare. But then I'm not sure how to use the comparison in a MySQL query to add/edit/delete the links.

Checkbox Array From Form - Shorthand For Looping The VALUES?
I am retreiving values from checkboxes in a form to decide where thumbnails and uploaded images get placed (same image goes in multiple directories). The following code works. But I wonder if there is a shorthand way to output the values in a while statment rather than a bunch of if statements. That is, is there a way to output ALL possible values (e.g., sports, group, 2002 - I have many others) in a loop? PHP Code:

Checkbox Array Passes To Script Fine But Doesn't Mail Right
I'm starting to get a little ticked off because I've worked for
hours on this and I can't seem to find the cause. I'm using PHP 5.1.6.
I'm trying to get the values of some form checkboxes along with another
fixed variable and pass them along in an email. For demonstration
purposes, I have checked the Wed and Fri checkboxes and set the time for
9:00 am.

<FORM ACTION="test.php" METHOD=POST>
<TABLE border="1" width="70%" >
<TR>
<td><input type="checkbox" name="NewClass[]" value="Mon" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Tue" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Wed" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Thu" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Fri" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Sat" size="5"
maxlength="2"</td>
<td><input type="checkbox" name="NewClass[]" value="Sun" size="5"
maxlength="2"</td>
<TD><input type="text" name="NewClass-Time" size="5" maxlength="10"></TD>
</TR>
</TABLE>
<input type="submit" name="ClassList" value="Submit Survey Info"
class="button">
</form>

When I print out print_r($_POST);, I get everything passed correctly as:

Array
(
[NewClass] =Array
(
[0] =Wed
[1] =Fri
)

[NewClass-Time] =9:00 am
)

But when it gets emailed, the results listed on the email I get are as
follows:

NewClass: Array

NewClass-Time: 9:00 am

I stripped the processing script down to the barest of essentials. All
that's on it right now is:

foreach($_POST as $key =>
$value){if(!(!isset($value))){$set=1;}$message = $message . "$key:
$value

";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$message = stripslashes($message);

$headers = "From: " . $_POST['name'] . " <" .$_POST['email'] . ">
" .
"Return-Path: " . $_POST['email'] . "
" . "Reply-To: " .
$_POST['email'] . "
";

mail($my_email,$subject,$message,$headers);

Sending Extracted Array Data From MySQL To Checkbox
I have a list of checkboxes set up as a form that stores the data to a database cell in a comma separated string: For example: "12,13,18,110,118,21,28,31"

Each checkbox has a name of "categories" with different values. What I'd like to do is the following:

1) Extract the data from the database
2) Separate each number it into an individual array value
3) Make the checkboxes in categories.php reflect the selected or non-selected state, based upon the results from the database (selected being the numbers in the database)

Step 1 - I know how to do.
Step 2 - I assume I need to use the explode function, no?
Step 3 - Not a clue.... Code:

Onchange
I want to make a php document . I have comboxbox and checkboxes. I want that some checkboxes would appear,some don't changing to  which value chosen for combobox. As I learn I should use onchange ,but I don't know how to do.

Change A Variable Value Upon OnChange Method
I use a combo box 'select' in a form, now, what I am going to do is to change an SQL statement when user change the value of the combo box.

I tried many ways and still it doesn't work.

May I know is there any efficient way to do it?

Calling Variable In Onchange Function
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the
select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database
for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?

This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'");
}

<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";document.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>


Newbie: Getting Index From Dropdown On Onchange Into Php Var
This is very new to me, scripting languages. I am trying to get the
/select id off of a dropdownlist, which really does not drop down and is
more like a flat list??, at an onchange event. Then move it into a php
var to retrieve different data from db. Not that it matters but I load
about 1200 items in to the list and was surprised how fast it is.

Could some one give me some direction?

//
// Handle the data coming back
echo "<FORM NAME=author>";
echo "<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK()>";
while ($rows = mysql_fetch_object($result)) {
echo "<OPTION VALUE=".$rows->id.">".
$rows->TITLE." ".
$rows->lastname.", ".
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
"</OPTION>";
}
echo "</SELECT>";
echo "</FORM>";
echo "<script language=Javascript>";
echo "function getPK() {";
<? $location ?=
"document.author.author_pk.options[document.author.author_pk.selectedIndex].value
";
echo "}";
echo "</script>";

PHP PRINT Statement With OnChange Event
I have tried every variation of the "onchange" statement below without
any actual reloading of the page. I am hoping that the PHP PRINT
statement is constructed wrong, otherwise it is javaScript error an
needs to be posted in the javaScript newsgroup.

The FireFox javaScript Console reports the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_scheme s.options[form.color_schemes.selectedIndex].value)

My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;

<?php
print "<select name='scheme' size=&#391;'
onchange='location.href=themes.php?scheme=(form.co lor_schemes.options[form.color_schemes.selectedIndex].value)'>";

//populate the dropdown selector box...
$counter = 1;

foreach ($schemes as $scheme)
{
if ($selected_theme == $counter)
print "<option value = '$counter' selected>$scheme</option>";
else
{
print "<option value = '$counter'>$scheme</option>";
}
$counter ++;
}
?>

Call PHP Form Onchange Event
I have a trouble when i want to use a list box, I want when I choose an item on it then data in textarea'll change too.

Linking Php Function In Onchange Event
i have probelm in linking php function in onchange() event. I am new to php. Im my database (test) ,i have per_det as table whic have two cloumn(eno, ename). My query is list all eno from database in combo box. when user select the eno the respective name from database should be displayed in textbox, Code:

Select Menu OnChange To Update Text Boxes
I've a select menu filled from mySql, So when I change the selection.. I want to change 3 text boxes also by the same row of database that is = to the row of the select menu.

So i tried a lot but failed.. cuz I cant send to javascript the updated values when the selected menu change.

Checkbox
I am trying to make a form with 16 different checkboxes that pass on to an email. Someone got me started with the form but I'm not sure how to incorporate it into my php file.

<INPUT name=other_needs[] type=checkbox id="other_needs[]" value=reception>Reception<TD>

<TD><INPUT name=other_needs[] type=checkbox id="other_needs[]" value=Lunch>Lunch</TD>

How do I refer to the checkboxes in my php file to include the results in the email the script sends?

Checkbox And SQL
What im stuck with at the moment is how to update the SQL database with the new information acquired from a set of check boxes.

What i´ve done so far is to create the checkboxes and got the information from a table which checkboxes is needed and pre check it if it is already enabled. i have two rows in the database 1. Module_Name (name of a module) 2. is_enabled (is the module enabled 1 or 0). Code:


Checkbox Value
if i have 10 checkbox for customer interest..  how do i save that to database?? need to create 10 fields in the database??  after save.. how to display back when customer view his data.. if i choose swimming.. next time when i view back.. how to show swimming in the checkbox being checked

Checkbox
I have a database column which either holds the value 1 or 0.

Now if there is a 1 in this column I want to produce a checkbox button that is ticked, and if a 0 then nothing ticked.  So I thought it would work like this:

<input name="dayTwo[]" type="text" id="dayTwo" value="<?php echo $databaseArray['d2']?>" size="6" />

However, it does not seem to work?

Checkbox
I am creating an email form with checkbox included.

And I need the checkbox to be ticket when I enter the form though links.

IE

List of checkbox's

checkbox 1
checkbox 2
checkbox 3
checkbox 4

say I was another page and I click on a link (call the link checkbox 1) I would like the checkbox to be ticked automatically. I know this makes no sense but I hope you get the idea.

Checkbox
i have a checkbox array of some unknown size.its a dynamic array created.
i want to know out of all checkboxes how many r selected and which are they?
and then insert the data in the table based on that. i hav written the code as follows:-

<?
$no=0;
$friendname= $_POST['friendname'];
$storecount=$_POST['storeid'];
while($no<$storecount)
{
   if($friendname[$no])
   {
      $sql = "INSERT INTO groupfriends (groupid, username) VALUES ('$stid[$no]', '$friendname[$no]')";

      $result = mysql_query($sql) or die('Query

failed. ' . mysql_error());
   }
   $no=$no+1;
}
?>

i dont think this will work.it will add all the checkoxes data to the table. i want to insert only of those which r selected.

Checkbox Values
Basically, I have 2 checkbox's which are printed out for each record within my table. On the next form, each checkbox is tested for being "checked" and the database is updated accordingly.

This is fine. My problem is that I dont want users to be able to select both check-box's at the same time. After talking to "andnaess" on an earlier post and doing some reading, I decided upon using some javascript to do what i wanted.

I have found a script which does exactly what i want, and i am now incorporating it into my original php script.

I am having problems assigning a name and value variable with an array to my checkbox's. Is this possible, or have i got the wrong idea?

Checkbox Confusion!!!!
I have page1.php that displays some articles from a database by the condition 'on'

What I want to do is have checkboxes so that the articles you check won't be displayed on the web page the next time it's brought up. Essentially turn the articles checked to the 'off' condition and leave the articles that are not checked to the 'on' condition.

When you hit the submit button I want it to go to a page2.php to run an update query to change the 'on' condition to the 'off' condition for the specific articles that were previously checked. (My Primary Key in the database is Article_Number)

I think i have page1.php correct (don't quote me on this!)

<input type='checkbox' name='Display_Article' value='off'>";

But I'm completely lost on what to do for the page2.php

if($submit) {

for ($i=0; $i<count($Display_Article); $i++) {
//echo "<li>".$Display_Article[$i]."</li>";

$sql="Update articles set Display_Article='$Display_Article[$i]' where Article_Number='$Article_Number'";
$result=mysql_query($sql) or die ("Update Query Failed");
}

Checkbox Problem?
I am having trouble with checkboxes. How do you have a checkbox that it it is not checked it will still allow the form to be submitted. I am using checkboxes now, and if all the checkboxes are not checked, then it says that each of the ones that aren't checked are undefined variables why?

Problem With Checkbox
When i click on submit then the table wont be updated. I wanted to try to update the colom aw with the desired awardsid but i also wonder what happens if i have selected 2 or more checkboxes and whats entered then in the table aw, 1 & 2 or ? PHP Code:

Retain Checkbox Value
Just a quick question regarding the way to do something rather than the
actual code :-

I have a page which has some links that go through to a HTML form and
each link will check a certain checkbox. I want the form to retain the
checked status of any checkboxes that are set to checked when the user
goes back to the previous page.

Would this be best done using sessions or is there another way I could
use? I don't mind using sessions as I have used them before. I would
like to avoid using cookies but I don't really have any strong
objections to using them, it's just that they're not 100% reliable (but
then, what is?).

CheckBox Question
i started a php site in dreamweaver and i try fill data into MySql
database.

i set up a page with a form and i can fill in all the fields.

just for one field, i like to have several checkboxes. every checkbox
has a value, and they should fill the same field with their vale when
checked. i also want to keep my text box, so i can write additional
information.

at the moment, when i click more than one checkbox, only the value of
the first checkbox appears in the database. also, if there is already
some data in this cell, it delete previous data, but i would like to
keep it. preferably it should just add to information allready in the
database.

Disable Checkbox
I have a checkbox that I set by php code to be either "checked" or "".
I want to disable the ability of the user to check or uncheck it. I
tried "readonly", but that didn't work.

Checkbox Problem !
I try to display the multiple checkbox in my form and the quantity of this are depends on how many records in my database (usually the record is more than 500). So how big space it takes to display. And to solve the spaces problem, i thing i better display with horizontal scrollbar to save the space. But i don't know to do it.

Checking A Checkbox
Is it possible to preset the values of form elements with php - so that when
the client gets the page certain boxes are checked or completed - on the
fly - based on their HTML id.

Javascript has a way of doing this - but i need the functionality of PHP
too - so if i can move the whole thing over to php it owuld be better .

javascript example -

document.forms['form1'].elements['radiobuttonno'].checked = true;

Checkbox Not Between Date
I get a database for « News » on Internet.
Side Admin, I would like a form to know witch "News" are Online or
not.

In my database mysql I get :

Date_start
and
Date_end

Outside this date, the « News » are unvisible.

In my form I put a checkbox « Off_line »

If it's check, all the news outside Date_start
And Date_end must be visible.

I tryed like this

In Head :
<?php
if (isset($HTTP_GET_VARS["date_off"]))
{
$ date_off =$HTTP_GET_VARS["date_off"];
}
else
{
$ date_off =0;
}
?>

In my form for checkbox :
<input <?php if ("CURRENT_DATE NOT BETWEEN $row_R_news['date_start']
AND $row_R_news['date_end'] ",1) {echo "checked="checked"";} ?>
name=" date_off " type="checkbox" id=" date_off " value="1">

For my request sql :
SELECT t_news.*
FROM t_news
WHERE $date_off

Checkbox Is Checked
how do u say that if the checkbox is checked, than do something.

Checkbox FormMailer
Ive got this problem and i have no idea how to fix it. Ive been trying to do it in PERL, but thats not my strong point, and i know a lot more PHP than perl. But still dont know enough to try and achive what i want to do.

Basically i am trying to have a web form in which the company fills out the form and can select which people to send the form to. Code:

$_POST Checkbox
I'm trying to create a validate members page that lists all the unvalidated members and beside it is a checkbox with the name attribute being the member's name. Is there a way to create a foreach loop to check all the $_POST and check if it's empty, and if not, do something?

For Each None Checked Checkbox
I need help with foreach none checked checkbox as value, can you even do that. I tryed the !isset(); function but i'm not sure it would work because the none checked box would not of run with the $_POST ( i think ) this is an example table of what i'm looking for help with:

({num}) = the value
[] = the checkbox.

(1)(2)(3)(4)
 [] []  [] []

the person checks the one(s) they wish to keep and the none checked ones get swaped for diffrant values. I'm not quite sure if it is possible, but i will ask anyway to see if anyone as a solution.

Checkbox Blues
I have the following checkboxes where I am using an array called check[] ...

<input name = "check[]" type = "checkbox" value = 'somevalue1' />
<input name = "check[]" type = "checkbox" value = 'somevalue2' />
<input name = "check[]" type = "checkbox" value = 'somevalue3' />

When selected by the user, I wish to delete the selected records using this code ...

// capture checkbox data
$data = $_POST['check'];

// start delete loop
foreach ($data as $key => $value )
   {
    // create SQL string
    $SQL = 'DELETE FROM ' . $table . ' WHERE name = "' . $value .'"';
   
    // run SQL query
    code goes here
   }

This code works fine ! BUt the javascipt functionality that references it does not work ! What I would like to know is how I can do the same thing but AVOID using the check[] array, by using checkboxes like this ...

<input name = "check" type = "checkbox" value = 'somevalue1' />
<input name = "check" type = "checkbox" value = 'somevalue2' />
<input name = "check" type = "checkbox" value = 'somevalue3' />

Has anyone got any good references for dealing with checkboxes in php ?

Checkbox Data In The Database
I want to display the checkboxes taken from the database from table “const_skills”, but the checkboxes and its values do not appear ($html_skills). Can anyone figure this out. Below is the codes that I’ve been using.
Thanks in advance.

<?php
include "dbinfo.php3";

function get_checkbox_labels($table_name) {
/* make an array */
$arr = array();

/* construct the query */
$query = "SELECT * FROM $table_name";

/* execute the query */
$qid = mysql_query($query);

/* each row in the result set will be packaged as
an object and put in an array */
while($row= mysql_fetch_object($qid)) {
$array[count($arr)] = $row;
}
return $arr;
}

/* Prints a nicely formatted table of checkbox choices.
$arr is an array of objects that contain the choices
$num is the number of elements wide we display in the table
$width is the value of the width parameter to the table tag
$name is the name of the checkbox array
$checked is an array of element names that should be checked
*/

function make_checkbox_html($arr, $num, $width, $name, $checked) {

/* create string to hold out html */
$str = "";

/* make it */
$str .= "<table width="$width" border="0">n";
$str .= "<tr>n";

/* determine if we will have to close add
a closing tr tag at the end of our table */
if (count($arr) % $num != 0) {
$closingTR = true;
}

$i = 1;
if (isset($checked)) {
/* if we passed in an array of the checkboxes we want
to be displayed as checked */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id"";

reset($checked);
while (list(, $entry)=each($checked)) {

if ($entry == $ele->id) {
$str .= "checked";
continue;
}
}
$str .= ">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}

} else {
/* we just want to print the checkboxes. none will have checks */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}
}
/* tack on a closing tr tag if necessary */
if ($closingTR == true) {
$str .= "</tr></table>n";
} else {
$str .= "</table>n";
}
return $str;
}
/* get the checkbox labels */
$skills = get_checkbox_labels("const_skills");

/* create the html code for a formatted set of
checkboxes */
$html_skills = make_checkbox_html($skills, 3, 400, "skills[]",$checked);
?>

<html>
<body bgcolor="#ffffff" text="#000000" id=all>
<br>
<form name="skills" method="POST" action="insertskills.php3">
Check off your web development skills:
<? echo "$html_skills"; ?>
<br>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Record Unchecked Checkbox
Is there a way to record a checkbox that is not checked?

Smarty: Checkbox Validation
I have smth. like this:

file.php:
<?php

SmartyValidate::connect($smarty);
//SmartyValidate::register_form('register');

$smarty->assign('nl_id',0);
$smarty->assign('nl_sel',$Fnewsletter);
$smarty->assign('nl_name','Fnewsletter');
$smarty->assign('pp_id',0);
$smarty->assign('pp_sel',$pp);
$smarty->assign('pp_name','Fnewsletter');

if(SmartyValidate::is_valid($_POST) == true) {
// Register

} else {
// Form displayed with hints ex. "You forget e-mail"
$smarty->assign($_POST);
$smarty->display("register_form.tpl");
}

?>

Theme.tpl

{$duplikacja_usera}
<p>{validate field="Flogin" criteria="notEmpty" message=" Podaj
login "}</p>
<p>{validate field="Fhaslo" criteria="notEmpty" message=" Podaj
hasL,o "}</p>
<p>{validate field="Fhaslo" criteria="isEqual"
field2="Fhaslorepeat" message=" HasL,o nie zgadza siÄ™ z
powyLLszym "}</p>
<p>{validate field="Fimie" criteria="notEmpty" message=" Podaj imie
"}</p>
<p>{validate field="Fnazwisko" criteria="notEmpty" message=" Podaj
nazwisko "}</p>
<p>{validate field="Fmail" criteria="isEmail" message=" Podaj
poprawny e-mail "}</p>
<p>{validate field="Fulica" criteria="notEmpty" message=" Podaj
ulice "}</p>
<p>{validate field="Fnumer" criteria="notEmpty" message="Podaj
numer domu "} </p>
<p>{validate field="Fkod" criteria="notEmpty" message=" Podaj kod
pocztowy "}</p>
<p>{validate field="Fmiasto" criteria="notEmpty" message=" Podaj
miasto "}</p>
<BR>
<form name="register" onsubmit="return check(this)"
action="index.php/mode/register" method="POST">
<input type="hidden" name="akcja" value="rejestruj">
<input type="text" name="Flogin" value="{$Flogin}" maxlength="20"
class="login_in" style="width:150px"></div>
<input type="password" name="Fhaslo" maxlength="20" class=""
class="login_in" style="width:150px"></div>
<input type="password" name="Fhaslorepeat" maxlength="20" class=""
class="login_in" style="width:150px">
<input type="text" name="Fimie" value="{$Fimie}"
maxlength="20" class="login_in" style="width:150px">
<input type="text" name="Fnazwisko"
value="{$Fnazwisko}" maxlength="100" class="login_in"
style="width:150px">
{validate field="Fnazwisko" criteria="notEmpty"
message=" Podaj nazwisko "}</div>

{html_checkboxes name="Fnewsletter" values=$nl_id
selected=$nl_sel}..........


Copyright © 2005-08 www.BigResource.com, All rights reserved