Getting list of checkboxes and value in next page

This is a discussion on Getting list of checkboxes and value in next page within the PHP Language forums, part of the PHP Programming Forums category; Plz help me.Problem is that On the first page I display all other user with checkbox and give user ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-06-2007
jeet
 
Posts: n/a
Default Getting list of checkboxes and value in next page

Plz help me.Problem is that On the first page I display all other user
with checkbox and give user option to select only two user which he
wants to send message. Tell me please how I'll get those checkboxes
value and name on the next page and send message to only those two
selected user.
Thanx in
advance

Reply With Quote
  #2 (permalink)  
Old 08-06-2007
dkruger
 
Posts: n/a
Default Re: Getting list of checkboxes and value in next page

On Aug 6, 7:15 am, jeet <jatindermash...@gmail.com> wrote:
> Plz help me.Problem is that On the first page I display all other user
> with checkbox and give user option to select only two user which he
> wants to send message. Tell me please how I'll get those checkboxes
> value and name on the next page and send message to only those two
> selected user.
> Thanx in
> advance


If you are wanting to limit the number of selections (so the user can
only select 2 etc), instead of using checkboxes, I would use radio
buttons or select lists. Anyway, after making the selections and
submitting your form, on the next page you can access the data
selected by using $value=$_POST["obj_name"]; where obj_name is the
name value on your form. With radio buttons, checkboxes, or select
lists the information placed in $value will be whatever you have setup
for the form objects value, or option value. Use $_POST only if you
are using POST for the method to submit the form, otherwise if you use
GET for the method, use $_GET.

Reply With Quote
  #3 (permalink)  
Old 08-06-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Getting list of checkboxes and value in next page

jeet wrote:
> Plz help me.Problem is that On the first page I display all other user
> with checkbox and give user option to select only two user which he
> wants to send message. Tell me please how I'll get those checkboxes
> value and name on the next page and send message to only those two
> selected user.
> Thanx in
> advance
>


It's not too hard. In our first page, have something like:

<form name="form1" method="post" action="/page2.php">
<input type="checkbox" name="user[]" value="1">
<input type="checkbox" name="user[]" value="2">
<input type="checkbox" name="user[]" value="3">
<input type="checkbox" name="user[]" value="4">
</form>

In your second page, $_POST['user'] contain the data:

if (isset($_POST['user'])) {
if (count($_POST['user'])) > 2) :
echo "Too many users selected!";
}
else {
foreach ($_POST['user'] as $user) {
// validate and handle the data here
}
}
}
else {
echo "No users selected";
}




--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #4 (permalink)  
Old 08-07-2007
fssm2666
 
Posts: n/a
Default Re: Getting list of checkboxes and value in next page

On Aug 6, 9:10 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> jeet wrote:
> > Plz help me.Problem is that On the first page I display all other user
> > with checkbox and give user option to select only two user which he
> > wants to send message. Tell me please how I'll get those checkboxes
> > value and name on the next page and send message to only those two
> > selected user.
> > Thanx in
> > advance

>
> It's not too hard. In our first page, have something like:
>
> <form name="form1" method="post" action="/page2.php">
> <input type="checkbox" name="user[]" value="1">
> <input type="checkbox" name="user[]" value="2">
> <input type="checkbox" name="user[]" value="3">
> <input type="checkbox" name="user[]" value="4">
> </form>
>
> In your second page, $_POST['user'] contain the data:
>
> if (isset($_POST['user'])) {
> if (count($_POST['user'])) > 2) :
> echo "Too many users selected!";
> }
> else {
> foreach ($_POST['user'] as $user) {
> // validate and handle the data here
> }
> }
> }
> else {
> echo "No users selected";
> }
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================



A few points that you must keep in mind....

1. If you want to limit the number of selections to the user, one way
you can do this is with JavaScript. In that case, be sure that the use
of Name and Id properties of the checkboxes is ok. For example,
usually the name of a collection of checkboxes is
NAME='checkbox_name[]' and the id can be ID='checkbox_id_1'. Why?
Because the PHP script take the value of NAME as an array with
$_POST['checkbox_name'], and some function with JavaScript can limit
the number of selected options, using the ID (must be unique!!!!).
Only the selected options are submitting to the PHP script.
2. Be careful, the Radio control only accept one selection.
3. If you are using a Select Multiple control, be sure that you are
selecting every selected option before submitting the information of
the form.

I hope this help.

Sorry for my english.....

Felipe Silva. Chile.

Reply With Quote
  #5 (permalink)  
Old 08-07-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Getting list of checkboxes and value in next page

fssm2666 wrote:
> On Aug 6, 9:10 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> jeet wrote:
>>> Plz help me.Problem is that On the first page I display all other user
>>> with checkbox and give user option to select only two user which he
>>> wants to send message. Tell me please how I'll get those checkboxes
>>> value and name on the next page and send message to only those two
>>> selected user.
>>> Thanx in
>>> advance

>> It's not too hard. In our first page, have something like:
>>
>> <form name="form1" method="post" action="/page2.php">
>> <input type="checkbox" name="user[]" value="1">
>> <input type="checkbox" name="user[]" value="2">
>> <input type="checkbox" name="user[]" value="3">
>> <input type="checkbox" name="user[]" value="4">
>> </form>
>>
>> In your second page, $_POST['user'] contain the data:
>>
>> if (isset($_POST['user'])) {
>> if (count($_POST['user'])) > 2) :
>> echo "Too many users selected!";
>> }
>> else {
>> foreach ($_POST['user'] as $user) {
>> // validate and handle the data here
>> }
>> }
>> }
>> else {
>> echo "No users selected";
>> }
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================

>
>
> A few points that you must keep in mind....
>
> 1. If you want to limit the number of selections to the user, one way
> you can do this is with JavaScript. In that case, be sure that the use
> of Name and Id properties of the checkboxes is ok. For example,
> usually the name of a collection of checkboxes is
> NAME='checkbox_name[]' and the id can be ID='checkbox_id_1'. Why?
> Because the PHP script take the value of NAME as an array with
> $_POST['checkbox_name'], and some function with JavaScript can limit
> the number of selected options, using the ID (must be unique!!!!).
> Only the selected options are submitting to the PHP script.


And also check it on the server end in case the user has javascript
disabled.

> 2. Be careful, the Radio control only accept one selection.


Which is why I use checkboxes.

> 3. If you are using a Select Multiple control, be sure that you are
> selecting every selected option before submitting the information of
> the form.
>
> I hope this help.
>
> Sorry for my english.....
>


Your English is better than many Americans!

> Felipe Silva. Chile.
>



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:30 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0