473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing variables to fill a form

67 New Member
Hi :)

anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ?

maybe using (the process of passing variables to other pages - through url)

but how can i assign them to form variables ?
Aug 11 '07 #1
6 3288
Atli
5,058 Recognized Expert Expert
You could use PHP to create the form, passing the variables as you print it.

Like so:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   // Get the variables
  3.   $firstName = @$_GET['firstName'];
  4.   $lastName = @$_GET['lastName'];
  5.  
  6.   // Print the form
  7.   print '<form action="process.php" method="GET">';
  8.   print '  <input type="text" name="firstName" value="'. $firstName .'" /><br />';
  9.   print '  <input type="text" name="lastName" value="'. $lastName.'" /><br />';
  10.   print '  <input type="submit" />';
  11.   print '</form>';
  12. ?>
  13.  
Aug 11 '07 #2
coool
67 New Member
page.php
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. $items = "item1,item3";
  4. ?>
  5.  
  6. <a href="form.php?selectedItems=<?=$items?>" >View Form<a/>
  7.  
  8.  

form.php
Expand|Select|Wrap|Line Numbers
  1. <form name="selectionform" method="post" action="">
  2.  
  3.               <select  size="3" multiple name="selectedItems[]">
  4.                 <option value="item1">Item1</option>
  5.                 <option value="item2">Item2</option>
  6.                 <option value="item3">Item3</option>
  7.               </select>
  8.  
  9.               <input type="submit" value="View Result">
  10. </form>
  11.  
What I'm looking for is when user click "View Form" link, they get the for filled with items - i.e some items are alreay selected ---- then if the user want to deselect one of the items or select more items he should able to do that.. !

to check the result: - in form.php
[php]
if($_POST)
echo implode($_POST['selectedItems'],",");
[/php]

so what do you think ? having $_GET inside form.php will solve the problem ! .. but I've tried it and it doesn't work.. I didn't know how to handle the array and nothing selected !! .. can you take my sample code and add to it the proper things so it will work ! please
Aug 11 '07 #3
Atli
5,058 Recognized Expert Expert
Ok. You weren't that far off there.

You will have to create the form in PHP, so that you can print the items you select in the GET string.

That can be done like this:
Expand|Select|Wrap|Line Numbers
  1. // Print form header
  2. echo '<form name="selectionform" method="post" action="">';
  3. echo '<select size="3" multiple name="selectedItems[]">';
  4.  
  5. // Get items from GET
  6. $items = explode(",", $_GET['items']);
  7.  
  8. // Show each item
  9. for($x = 1; $x <= 3; $x++) {
  10.     // Check if it is seleted
  11.     $isSelected = false;
  12.     foreach($items as $item) {
  13.         if($item == "item". $x) {
  14.             $isSelected = true;
  15.         }
  16.     }
  17.  
  18.     // Print the item
  19.     if($isSelected) {
  20.         echo '<option selected value="item'. $x .'">Item'. $x .'</option>';
  21.     }
  22.     else {
  23.         echo '<option value="item'. $x .'">Item'. $x .'</option>';
  24.     }
  25. }
  26.  
  27. // Close the form
  28. echo '</select><input type="submit" value="View Result"></form>';
  29.  
Also, the $_POST['selectedItems'] is an array, so try this to view the results:
Expand|Select|Wrap|Line Numbers
  1. echo "<pre><b>Selected Items:</b>\n";
  2. foreach($_POST['selectedItems'] as $item) {
  3.     echo "\t$item\n";
  4. }
  5. echo "</pre>";
  6.  
Aug 11 '07 #4
coool
67 New Member
You had your code under the assuption of 1,2,3 for items..

but when I said item1, item2, item3 ..

I meant anything...

it's not a sequence.. items are different words..
Aug 11 '07 #5
Atli
5,058 Recognized Expert Expert
It doesn't really matter either way. I will never be able to write exactly the code you need, as this is your code.

You should be able to write what you need based on the code I posted above, all you need to do is edit the part where the options are printed into the form so that it prints the options you need while matching the items passed in the GET string.

I would reccomend building an array of all the items that should be listed and use a foreach loop to loop through it an print them. Just make sure you check if each item exists in the GET string and add a 'selected' parameter in the option tag if it does.
Aug 11 '07 #6
karthipan
1 New Member
hg
hg
gh
h

h

h
h

h
h

h
h

h
h
h

h
h
h


h
sdhg
fgj
f
Dec 29 '10 #7

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

Similar topics

1
7424
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in which users enter numbers to be calculated into a square footage cost. Upon submitting, the results page uses ASP to give the total and the chance to...
3
14913
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
6675
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage & "<br>"%> Exp <%'Response.Write GrantID & "<br>"%>
0
1359
by: Jason Steeves | last post by:
I have one .aspx form that my users fill out and this then takes that information and populates a second .aspx form via session variables. I need to screen scrape the second .aspx form and e-mail that off. I have figured out how to do the screen scrape but it e-mails a blank form with none of the session variables set. Is there a way to screen...
11
3463
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...
8
4400
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...
7
2773
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass variables, and can do so just fine with a URL, and $_GET. What I would like to learn, and be very adept at using is the Form functions and how you...
1
3261
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be irrelavent. My syntax is surely where I am going wrong. I'd like to be able to call this routine to read different values from another device. ...
1
2257
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function //////////////////////////////////////////////////////////////////////////////////// version 1 : using global variables ////////////////////////////////////////////////////////////////// var _textField, _divColorPicker; // global vars...
0
7496
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7941
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...
1
7452
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...
0
7784
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...
0
6014
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...
1
5354
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...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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

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.