Hi
I m using form like below
[HTML]<form action='' method = post>
<input type=text name=txt id=txt>
<select name=region id=region multiple>
<option value=1>ONE</option>
<option value=2>Two</option>
<option value=3>Three</option>
<option value=4>Four</option>
</select>
<input type=checkbox name=chkbox value=1>One
<input type=checkbox name=chkbox value=2>Two
<input type=checkbox name=chkbox value=3>Three
<input type=checkbox name=chkbox value=4>Four
<input type=submit name=summit value=Enter>
</form>[/HTML]
and I use the following code to get the values
[PHP]
echo "Text Field value = ". $_POST['txt'] . "<br>";
echo "Select Field values=".$_POST['region']. "<br>";
echo "Checkbox Field values=".$_POST['chkbox']. "<br>";
[/PHP]
Let I enter Hello in Text field, select One and Two from select field and Check Three and Four Check Boxes then the above PHP code show the following results
Text Field value=Hello
Select Field values=2
Checkbox Field values=4
where as I expect the follwoing
Text Field value=Hello
Select Field values=1,2
Checkbox Field values=3,4
Looking forword for Help
Thanks in advance
9 1753
When you give something a value you need to use quotations
Could you do a print_r($_POST) on the page that receives the submitted values and show us the output.
You shouldnt be able access $_POST['chxbox'] by simply doing that, because it should be a multidimensional array, as you have given all checkboxes the same name.
When you are submitting variables with same name, you got to submit them as array.
Use this instead...
[HTML]<form action='' method = post>
<input type=text name=txt id=txt>
<select name="region[]" id=region multiple>
<option value=1>ONE</option>
<option value=2>Two</option>
<option value=3>Three</option>
<option value=4>Four</option>
</select>
<input type=checkbox name="chkbox[]" value=1>One
<input type=checkbox name="chkbox[]" value=2>Two
<input type=checkbox name="chkbox[]" value=3>Three
<input type=checkbox name="chkbox[]" value=4>Four
<input type=submit name=summit value=Enter>
</form>[/HTML]
On the action page, write
[php]echo "<pre>";
print_r($_POST)
echo "</pre>";[/php] in the start and you can come to know how to manipulate the submitted data according to your requirement.
Regards,
Harpreet
PS: Keeping values of attributes in quotes is really important for a proper mark-up, as markus said.
Thanks for replying to All.
First Thing I don't want to print the values. This was just an example. If I want to save the values into database. If i set the the the method attribute of the form to get then I see the following URL
page.php?txt=Hello®ion=1®ion=2&chkbox=3&chkb ox=4
I seems not an array.
Second I also I also tried the following
[PHP]
echo $_POST['region'];
echo $_POST['region'][0];
echo $_POST['region'][1];
[/PHP]
Here the first and 2nd statements print same values while the 3rd statement doesn't print any thing. ( Assume that I select one and Two form List).
Third In ASP Every thing is OK.
response.write(request.querystring("region"))
this prints
1,2 And I need the same from PHP.
Please some more help
I didn't force you to print the values. It was just so that you could understand in what form is the data received by PHP, as this is not ASP (but far better than ASP)
and I think you didn't try what I said... <select name="region[ ]" id=region multiple>
And last of all, use method="post" instead of get.
Read the last post carefully and try what I said. That may help you.
Hi,
All the above posts asked you to do this.... -
<form action='test.php' method = post>
-
-
<input type=text name=txt id=txt>
-
-
<select name=region[] id=region multiple>
-
-
<option value=1>ONE</option>
-
-
<option value=2>Two</option>
-
-
<option value=3>Three</option>
-
-
<option value=4>Four</option>
-
-
</select>
-
-
<input type=checkbox name=chkbox[] value=1>One
-
-
<input type=checkbox name=chkbox[] value=2>Two
-
-
<input type=checkbox name=chkbox[] value=3>Three
-
-
<input type=checkbox name=chkbox[] value=4>Four
-
-
<input type=submit name=summit value=Enter>
-
-
</form>
-
To get the exact output you wanted i manipulated your PHP script a bit like this... -
echo "Text Field value = ". $_POST['txt'] . "<br>";
-
echo "Select Field values=".implode(",",$_POST['region']). "<br>";
-
echo "Checkbox Field values=".implode(",",$_POST['chkbox']). "<br>";
-
Implode will convert your array into string... and for reverse you can use Explode . To directly access array posted you can use foreach loop.
Regards,
RP
I didn't force you to print the values. It was just so that you could understand in what form is the data received by PHP, as this is not ASP (but far better than ASP)
and I think you didn't try what I said... <select name="region[ ]" id=region multiple>
And last of all, use method="post" instead of get.
Read the last post carefully and try what I said. That may help you.
Thanks for helping <select name="region[ ]" id=region multiple>
I really forget to place [] braces after the name.
Thanks once again
I read somewhere that assigning the same name to an element automatically turned it into an array (no need for []).
Hm, I must've read incorrectly.
This post could've been resolved in your first reply, hs. If only people would listen :P
Not in PHP.... might be in ASP.
Try this... [php]//show_post.php
if (!isset($_POST['submit']))
{
echo "<from action=\"show_post.php\" method=\"post\">";
for ($i=0; $i<10; $i++)
echo "<input type=\"text\" name=\"markus\">";
//For the second time, use markus[] instead of markus
echo "<input type=\"submit\" name=\"submit\" value=\"Let's test\"></form>";
}
else
{
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>[/php]
Elaboration ;)
... yeh... you are right... just in first reply..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bmgx |
last post by:
I would like to use an already existing online service (currency
converter) basically consisting of a html form with a few options that
is submitted and returns the results. I really don't know...
|
by: Il Khan |
last post by:
Hi, I have an asp application running on a dozen of winXP machines
configured as kiosks. This application stores its data on a MS access db. I
have the need to make some reports extracting data...
|
by: Michael Hill |
last post by:
Hi, folks.
I am writing a Javascript program that accepts (x, y) data pairs from
a text box and then analyzes that data in various ways. This is my
first time using text area boxes; in the past,...
|
by: Prakash Wadhwani |
last post by:
Here is a code snippet in my Report:
** Snippet starts here ************************
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As
Integer)
Dim sSQL As String, strSQL0 As...
|
by: steve_marjoribanks |
last post by:
This isn't strictly an XML problem but I thought someone might be able
to help!
As part of my degree I am working on a new data format for use in the
geotechnical engineering domain.
The data...
|
by: suresh Chowdary |
last post by:
Hi everyone,
i ahve the one table with 2 not null fileds ,in this one column accept certain values (1,2,3), and another column will accept (1m,2m,3m).
the problem is when the data extracting...
|
by: napolpie |
last post by:
----Messaggio originale----
Da: napolpie@tin.it
Data: 3-mag-2007
10.02
A: <python-list@python.org>
Ogg: problem with meteo datas
Hello,
I'm Peter and I'm new in python codying and I'm using...
|
by: Werner |
last post by:
Hi,
I try to read (and extract) some "self extracting" zipefiles on a
Windows system. The standard module zipefile seems not to be able to
handle this.
False
Is there a wrapper or has...
|
by: poolboi |
last post by:
hi guys
i've having some problem extracting data from a text file
example if i got a text file with infos like:
Date 2008-05-01 Time 22-10
Date 2008-05-01 Time 21-00
Date 2008-05-02 Time...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |