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 ?
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: -
<?php
-
// Get the variables
-
$firstName = @$_GET['firstName'];
-
$lastName = @$_GET['lastName'];
-
-
// Print the form
-
print '<form action="process.php" method="GET">';
-
print ' <input type="text" name="firstName" value="'. $firstName .'" /><br />';
-
print ' <input type="text" name="lastName" value="'. $lastName.'" /><br />';
-
print ' <input type="submit" />';
-
print '</form>';
-
?>
-
page.php -
-
<?php
-
$items = "item1,item3";
-
?>
-
-
<a href="form.php?selectedItems=<?=$items?>" >View Form<a/>
-
-
form.php -
<form name="selectionform" method="post" action="">
-
-
<select size="3" multiple name="selectedItems[]">
-
<option value="item1">Item1</option>
-
<option value="item2">Item2</option>
-
<option value="item3">Item3</option>
-
</select>
-
-
<input type="submit" value="View Result">
-
</form>
-
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
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: -
// Print form header
-
echo '<form name="selectionform" method="post" action="">';
-
echo '<select size="3" multiple name="selectedItems[]">';
-
-
// Get items from GET
-
$items = explode(",", $_GET['items']);
-
-
// Show each item
-
for($x = 1; $x <= 3; $x++) {
-
// Check if it is seleted
-
$isSelected = false;
-
foreach($items as $item) {
-
if($item == "item". $x) {
-
$isSelected = true;
-
}
-
}
-
-
// Print the item
-
if($isSelected) {
-
echo '<option selected value="item'. $x .'">Item'. $x .'</option>';
-
}
-
else {
-
echo '<option value="item'. $x .'">Item'. $x .'</option>';
-
}
-
}
-
-
// Close the form
-
echo '</select><input type="submit" value="View Result"></form>';
-
Also, the $_POST['selectedItems'] is an array, so try this to view the results: -
echo "<pre><b>Selected Items:</b>\n";
-
foreach($_POST['selectedItems'] as $item) {
-
echo "\t$item\n";
-
}
-
echo "</pre>";
-
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..
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.
hg
hg
gh
h
h
h
h
h
h
h
h
h
h
h
h
h
h Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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);
|
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>"%>
|
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...
|
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...
| |
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...
|
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...
|
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. ...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |