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!
I need to have the variables that are typed into a form, name, email, phone etc. still be in the form when the person returns to it from another page. I have been trying SESSIONS.
<?php
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['email'] = $_POST['email'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
}
?>
and this in the form.
<input type="text" name="name" value="<?=$name = $_POST['name'];?>" size="30" maxlength="40" />
This makes it stay in the fields of the form after you click submit but it is not there when you return to the page. I have <?php session_start(); ?> on each page that the person would go to.
After all, you're taking care to store the variable in the _SESSION scope, you should be checking there to prefill the form value, as the _POST scope will not persist between multiple requests.
Hi there, thank-you again for your help, but it still doesnt work. Would it have anything to do with fact that there is a lot of other code on the page as the info is going into a database and some of it returned to the same page. What I'm trying to do is set up an auction site for the NGO I volunteer for. I've got the first part working. You enter your name, phone, email, bid and name if you want it to appear. Click 'Make your Bid' and the amount of the bid and name show up on your screen immediately. Then you click back to the page where the auction items are (the new info is there too of course), 21small paintings. All that works fine. But if you want to raise your bid or even bid on another painting you have to fill out all of your details again. I really do want this to work, it's very frustrating. Peter
Hi there, thank-you again for your help, but it still doesnt work. Would it have anything to do with fact that there is a lot of other code on the page as the info is going into a database and some of it returned to the same page. What I'm trying to do is set up an auction site for the NGO I volunteer for. I've got the first part working. You enter your name, phone, email, bid and name if you want it to appear. Click 'Make your Bid' and the amount of the bid and name show up on your screen immediately. Then you click back to the page where the auction items are (the new info is there too of course), 21small paintings. All that works fine. But if you want to raise your bid or even bid on another painting you have to fill out all of your details again. I really do want this to work, it's very frustrating. Peter
<?php
session_start();
function form_value($name){
if(!empty($_POST[$name])) // Is there post?
$_SESSION[$name] = $_POST[$name]; // Set Session
if(!empty($_SESSION[$name])) // IF there is session
return $_SESSION[$name]; // return the value
return NULL; // No session? no value
}
$name = form_value('name');
$phone = form_value('phone');
$email = form_value('email');
Hi, Thank-you very much, I do appreciate all your help. It works beautifully. Just one little hang up though. When you have filled out the form and clicked 'send' the bid and the name changes as it should but the name moves into and overwrites the the email address?? Any idea why that happens? I've checked and rechecked that all the code is the same for all fields etc. but can find nothing wrong there. Peter
henry8 wrote:Hi, Thank-you very much, I do appreciate all your help. It works beautifully. Just one little hang up though. When you have filled out the form and clicked 'send' the bid and the name changes as it should but the name moves into and overwrites the the email address?? Any idea why that happens? I've checked and rechecked that all the code is the same for all fields etc. but can find nothing wrong there. Peter
If you can show us ALL of the relative code we should be able to help.