Solved

Problem with variable

Posted on 2001-06-08
10
206 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

12 Experts available now in Live!

Get 1:1 Help Now