473,699 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to make a form name a variable?

3 New Member
I'm building a chart, and it's going through a for loop, which creates new text boxes. I want to be able to save the information put in each text box in some sort of variable array.

Right now it's only letting me save the very last one in a variable I've named $memo. I thought that if I echoed $memo within the loop it would print out each text box's input, but it's only taking the last one and printing that to the screen the amount of textboxes that I have.

This is basically the code in the for loop which is in a form:
Expand|Select|Wrap|Line Numbers
  1. {
  2. <input type="text" size="5" name="memo" id="memo" value="" />
  3.  
  4. $memo = $_POST['memo']; 
  5. echo $memo;
  6.  
  7. }
  8.  <input type="submit" name="Save" value="Save" />
Is there a way to set up my text input so that I can do some sort of variable array, like
Expand|Select|Wrap|Line Numbers
  1. <input type="text" size="5" name=$memo[$i] id="memo" value="" />
  2. $i++;
Any suggestions? Thanks!

-Coco
Nov 27 '07 #1
5 2669
Lumpy
69 New Member
I am not sure if I completely understand what you are wanting to do, but anyway to answer what I think your question is, yes you can do something like that.

You would want to setup your memo variable something like this....

Expand|Select|Wrap|Line Numbers
  1.  
  2. $memo[] .= $_POST['memo'];
  3.  
  4.  
And that will create the array variable $memo and add each entry after the last one. So the first key in the array would be 0, or $memo[0].

Then to call the variables in the input section, you would simply use an echo statement something like....

Expand|Select|Wrap|Line Numbers
  1.  
  2. echo '<input type="text" size="5" name="'.$memo[$i].'" id="memo" value="" />';
  3.  
  4.  
Than each loop through, you will get a different name for that input, as long as you continue to increase $i.

Hope this helps!
Nov 27 '07 #2
pbmods
5,821 Recognized Expert Expert
To nitpick on Lumpy's post:

Expand|Select|Wrap|Line Numbers
  1. $memo[] .= $_POST['memo'];
  2.  
is technically not correct and will generate an E_NOTICE error, because this statement attempts to concatenate a variable that does not exist.

Expand|Select|Wrap|Line Numbers
  1. $memo[] = $_POST['memo'];
  2.  
is the correct method (and produces the expected result).
Nov 27 '07 #3
cocotheflyingnut
3 New Member
That's exactly what I want to do, but for some reason it isn't working. I want to echo out the $memo[] array of what was typed in each text box. Any suggestions to what I have done up? Right now it's not echoing out anything.


[PHP]<?
$memo[] = $_POST['memo'];

for($j=0;$j<=6; $j++){
echo '
<form name="saving" method="post" action="">
<td valign="top" height="50" class="Text"><p align="center">
<input type="text" size="5" name="'.$memo[$j].'" id="memo" value="" /></td>';

if(isset( $Save )){

echo $memo[$j];


}

}
echo '</tr>

<input type="submit" name="Save" value="Save" />
</form>';
?>[/PHP]
Nov 28 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, Coco.

Try this instead:
Expand|Select|Wrap|Line Numbers
  1. ?>
  2. <form name="saving" method="post" action="">
  3. <table>
  4.     <tr>
  5. <?php
  6.     for( $j = 0; $j < 6; ++$j )
  7.     {
  8. ?>
  9.         <td valign="top" height="50" class="Text">
  10.             <p align="center">
  11.                 <input type="text" size="5" name="memo[]" value="" />
  12.             </p>
  13.         </td>
  14. <?php
  15.     }
  16. ?>
  17.     </tr>
  18. </table>
  19.  
When the User submits the form, $_POST['memo'] will contain an array.
Nov 28 '07 #5
cocotheflyingnut
3 New Member
Thank you! That made my program work perfectly!

JOSH
Nov 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6020
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to be played with - this is not the final result so please (unless it's leading to the script failure)...
13
74100
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide Form1.Visible = False Load (Form1)
14
2219
by: Oleg | last post by:
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two radiobuttons with values 'Via Email' and 'Printed Brochure'.
2
9247
by: umashd | last post by:
Hi, I am doing a web based project for my graduation. I studied bit of java for backend processesing and javascript for the client. Here is the scenario. In the FORM, I use INPUT TYPE=text VALUE=" " NAME=cat, and a gif next to it. User will click on the icon to get a new window. In the new window, the user selects a value from the pull down menu (created by servlet from back end) and clicks OK. The value is passed back to the
11
3476
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code and zipid are both passed to the lookup form/dialog by reference. I...
8
4413
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code is passed to the lookup form/dialog by reference. I then load a...
21
1766
by: Just Me | last post by:
I've tried in a few places using a variable name Form and it appears to be OK. For example: Public Shared Sub WritePositionsInRegistry(ByVal Form As Form, ByVal SubkeyName As String) Is it OK to use a Type name as a variable name. For example,: Set(ByVal Color As Color)
6
6329
by: Leszek | last post by:
Hi. I wrote a script: function zmiana(ile){ while(document.getElementById('accomp').childNodes.length>1){ ostatni=document.getElementById('document.dane.accomp').lastChild; document.getElementById('document.dane.accomp').removeChild(ostatni);
4
7264
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm using an include to pull in form elements (text fields, checkboxes, etc...) multiple times on a single page. The included page does not have a form tag of it's own, but the root page has uniquely named forms for validation. Imagine it like this:
4
2632
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered before the list is repopulated. For example, suppose the user selects 3 in the drop down list and 3 text fields are shown. If the user populates the 3 text fields with data and decides to change the drop down to a list of 4 or 5, how do I capture...
0
9196
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8896
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7784
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.