Jump to content

Recommended Posts

I'm not sure I understand you 100% correctly, but here is what I think you wanna do:

 

page.php

<?php
//These might come from a database or something
$name = "Firstname Lastname";
$age = "1337";
$email = "an@email.com";
?>

<form action="" method="">
    <input type="text" name="name" value="<?php echo $name;?>">
    <input type="text" name="age" value="<?php echo $age;?>">
    <input type="text" name="email" value="<?php echo $email;?>">
</form>

 

This will fill out the form with the values of $name, $age, $email. If you have the variables defined on page1.php and want to use them on page2.php I think you should use sessions:

 

page1.php

<?php
//Start a session
start_session();

//These might come from a database or something
$name = "Firstname Lastname";
$age = "1337";
$email = "an@email.com";

//Store the vars as session vars
$_SESSION['name'] = $name;
$_SESSION['age'] = $age;
$_SESSION['email'] = $email;

?>

 

page2.php

<?php
sessioin_start()
?>

<form action="" method="">
    <input type="text" name="name" value="<?php echo $_SESSION['name'];?>">
    <input type="text" name="age" value="<?php echo $_SESSION['age'];?>">
    <input type="text" name="email" value="<?php echo $_SESSION['email'];?>">
</form>

 

 

 

but mine isn't only text ! .. I have select statements..

 

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.