Solved

Problem with variable

Posted on 2001-06-08
10
220 Views
Last Modified: 2008-03-06
The form in html file below:

<form name="myform" method="post" action="yuhuu.php">
<input type="text" name="text[1]">
<input type="text" name="text[2]">
<input type="text" name="text[3]">
<input type="text" name="text[4]">
<input type="submit" name="submit" value="Send">
</form>

i'm sure the variable that receive by yuhuu.php is array.
But how if my form like below and i need the value add to other variable with array type ? And the name of variable is $text.($text is array)

<form name="myform" method="post" action="yuhuu.php">
<input type="text" name="text1">
<input type="text" name="text2">
<input type="text" name="text3">
<input type="text" name="text4">
<input type="submit" name="submit" value="Send">
</form>

0
Comment
Question by:fajr_n
10 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 6168052
If you use name="text[1]" then the array will be called text and element 1 will have the value of the HTML form field.

No problem.

If you already have an array called text with some elements there, I think you should be able to do ...

<form name="myform" method="post" action="yuhuu.php">
<input type="text" name="text[]">
<input type="text" name="text[]">
<input type="text" name="text[]">
<input type="text" name="text[]">
<input type="submit" name="submit" value="Send">
</form>


This will add the entries onto the end of the array for you.

Regards,

Richard Quadling.
0
 
LVL 8

Expert Comment

by:us111
ID: 6169735
yes <input type="text" name="text[]">
0
 
LVL 1

Author Comment

by:fajr_n
ID: 6170028
you all rigth.
But I need the modification not in the form file. I need the resolve in yuhuu.php.

yuhuu.php still receive $text1, $text2, $text3 and $text4. And it will create new variable with name $text in array type. Each variable from form (last form in my question)will add to each variable in array variable.

$text1 -> $text[1]
$text2 -> $text[2]
$text3 -> $text[3]
$text4 -> $text[4]

is it possible ?

I already read in manual about variable variables. I see something relate in there. But my head still spin :(

the reason why i need the form still like that, because i need change the value in each text box with javascript. If the name the text box in array, javascript tell me the text box not 'object'. So I try modify the php file.
0
 
LVL 1

Author Comment

by:fajr_n
ID: 6170030
you all (RQuadling  and us111) rigth.
But I need the modification not in the form file. I need the resolve in yuhuu.php.

yuhuu.php still receive $text1, $text2, $text3 and $text4. And it will create new variable with name $text in array type. Each variable from form (last form in my question)will add to each variable in array variable.

$text1 -> $text[1]
$text2 -> $text[2]
$text3 -> $text[3]
$text4 -> $text[4]

is it possible ?

I already read in manual about variable variables. I see something relate in there. But my head still spin :(

the reason why i need the form still like that, because i need change the value in each text box with javascript. If the name the text box in array, javascript tell me the text box not 'object'. So I try modify the php file.
0
 
LVL 1

Author Comment

by:fajr_n
ID: 6170154
below the javascript to use:

<script>
function checkAll()
{
  for (var j = 1; j <= 2; j++)
   {
      box = eval("document.mydocument.text" + j );
      if (box.value == "") box.value = "yuhuu";
   }
  for (var i = 1; i <= 2; i++)
   {
      box = eval("document.mydocument.text" + i );
      if (box.value == "") box.value = "yihaa";
   }
}
</script>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:fajr_n
ID: 6170169
ups ...
the truth is 'document.myform'. not 'document.mydocument'

:)
0
 
LVL 1

Accepted Solution

by:
mubarmej earned 100 total points
ID: 6170486
This is the code in PHP :


$i=1;
while (isset(${"text".$i})) {
    $text[$i] = ${"text".$i};
    $i++;
}

0
 
LVL 8

Expert Comment

by:us111
ID: 6170609
yes
0
 
LVL 1

Author Comment

by:fajr_n
ID: 6175884
You're rigth mubarmej ... thx. You got your point. Watch my question with title 'For mubarmej'. Because I need others can see this threads :)
0
 
LVL 1

Author Comment

by:fajr_n
ID: 6179814
Thank's ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now