Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

PHP/HTML: saving form data once entered

$
0
0

I have a PHP webpage with basic HTML, which includes form, where user can enter some data. The form can be filled in by user directly, but can also be auto-filled via GET method, returned by one of the actions which are called from original PHP webpage. Problem is, after the form gets auto-filled, if any other action is called on the webpage (external php pages; non of those actions actually result in leaving the webpage), the form data gets deleted and user is left with blank fields. I would like to have data in the form saved and always displayed once entered. I tried using $_SESSION after variables arrive via GET method to save array of values, but it is not working for me:

<?php if (isset($_GET['decrypted'])) : ?>

<?php session_start(); 
$_SESSION['saved'] = array();

// Add items based on item ID
$_SESSION['saved'][$decrypt_data] = array('s_id' => $_GET['s_id'], 'u_id' => $_GET['u_id'], 'l_id' => $_GET['l_id'], 'cu_id' => $_GET['cu_id']);

?>

...

<form action="./execute.php">
    <p>2) Select options:</p>
    <input type="radio" name="mode" value="one">one<br>
    <input type="radio" name="mode" value="two">two<br>
    <p></p>
    s ID: <br><input type="text" name="s_id" value="<?php echo $_SESSION['saved'][decrypt_data]['s_id'] ?>"><br> 
    u ID: <br><input type="text" name="u_id" value="<?php echo $_SESSION['saved'][decrypt_data]['u_id'] ?>"><br> 
    l ID: <br><input type="text" name="l_id" value="<?php echo $_SESSION['saved'][decrypt_data]['l_id'] ?>"><br>
    cu ID: <br><input type="text" name="cu_id" value="<?php echo $_SESSION['saved'][decrypt_data]['cu_id'] ?>"><br>
    <p></p>
    <input type="submit" value="Do it!">
    </form>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>