Passing variables to fill a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coool
Forum Commoner
Posts: 45
Joined: Wed Jul 11, 2007 5:51 pm

Passing variables to fill a form

Post by coool »

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 ?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g. <input type="text" name="xyz" value="the default value" />
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Passing variables to fill a form

Post by superdezign »

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

but how can i assign them to form variables ?

Code: Select all

// page.php?foo=value

<input type="text" name="foo" value"<?php echo isset($_GET['foo']) ? $_GET['foo'] : '';?>" />
coool
Forum Commoner
Posts: 45
Joined: Wed Jul 11, 2007 5:51 pm

Post by coool »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[b]page.php[/b]

Code: Select all

<?php
$items = "item1,item3";
?>

<a href="form.php?selectedItems=<?=$items?>" >View Form<a/>

form.php

Code: Select all

<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

Code: Select all

if($_POST)
	echo implode($_POST['selectedItems'],",");
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


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

coool wrote: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.. !
How do you determine which should be pre-selected? Database? A different form? Is it the same every time?
coool wrote:can you take my sample code and add to it the proper things so it will work ! please
... No.
coool
Forum Commoner
Posts: 45
Joined: Wed Jul 11, 2007 5:51 pm

Post by coool »

well, in the form there's nothing selected

but as soon as the user click "view form" i need to pass by url some variables to be selected in the form when the user look at it.. and then he can modify the selections/add/remove/etc..


it's similar to have:

Group A has item1 and item2 selected
------------> view form

Group B has item 3 and item 2 selected
-------------> view form

etc..
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Then you'll want to post to the selected items to the next page with 'View Form' as the submission button. Then, depending on how you handle it, use the select values to determine which values are selected in the next page.
coool
Forum Commoner
Posts: 45
Joined: Wed Jul 11, 2007 5:51 pm

Post by coool »

but I don't have a form in my first page to use a submission button

and then even if i do that how can i handle the selected items/things in the form (second page)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

coool wrote:but I don't have a form in my first page to use a submission button
Then make one. If they can select data, why wouldn't you make it a form? How else did you expect to pass the data?

coool wrote:and then even if i do that how can i handle the selected items/things in the form (second page)
print_r($_POST) and work from there.
Post Reply