Solved

Problem with variable

Posted on 2001-06-08
10
231 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: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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 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…

832 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