Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

keep value after submit php

// Author: Rimon(ProgrammerRimon), this code was pasted by ProgramemrRimon
// Date: 2022-02-19, 3:29 AM GMT + 6
<?php

if (isset($_REQUEST['f'])) echo 'Fruits: ' . $_REQUEST['f'];
echo "<br>";
if (isset($_REQUEST['v'])) echo 'Vagetables: ' . $_REQUEST['v'];
global $v, $f;
$f = ['apple', 'banana', 'papaya', 'mangos', 'carrot', 'grapes', 'guava', 'strawbarries', 'watermelons', 'Pomegranates'];
$v = ['lettuce', 'cabbage', 'onion', 'garlic',  'Asparagus', 'Rhubarb', 'Celery', 'Spinach', 'Arugula', 'Broccoli'];
function s($a, $n)
{
    $s = '';
    foreach ($a as $key => $value) {
        if (isset($_REQUEST[$n])) {
            if ($_REQUEST[$n] == $value) {
                $s = 'selected';
            } else {
                $s = '';
            }
        }
        echo "<option $s value='" . $value . "' >$value</option>";
    }
}
?>
<form action="" method="post">
    <select name="f" id="">
        <?php s($f, 'f'); ?>
    </select>
    <br>
    <select name="v" id="">
        <?php s($v, 'v'); ?>
    </select>
    <input type="submit" value="Submit">
</form>

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #submit #php
ADD COMMENT
Topic
Name
9+2 =