Solved

Problem with variable

Posted on 2001-06-08
10
239 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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 …

830 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