?
Solved

Problem with variable

Posted on 2001-06-08
10
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

719 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