Page 1 of 1
Passing variables to fill a form
Posted: Sat Aug 11, 2007 9:13 am
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 ?
Posted: Sat Aug 11, 2007 9:19 am
by volka
e.g. <input type="text" name="xyz" value="the default value" />
Re: Passing variables to fill a form
Posted: Sat Aug 11, 2007 9:31 am
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'] : '';?>" />
Posted: Sat Aug 11, 2007 10:07 am
by coool
feyd | Please use 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
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]
Posted: Sat Aug 11, 2007 10:48 am
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.
Posted: Sat Aug 11, 2007 12:22 pm
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..
Posted: Sat Aug 11, 2007 12:50 pm
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.
Posted: Sat Aug 11, 2007 1:11 pm
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)
Posted: Sat Aug 11, 2007 8:33 pm
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.