I would like to validate my form and set the given values back to the input fields.
This is what var_dump($_GET) returns when I send the form:
array(10) {
["ich_vorname"]=> string(5) "sdfdf"
["ich_name"]=> string(0) ""
["ich_strasse_nr"]=> string(0) ""
["ich_plz_ort"]=> string(0) ""
["ich_email"]=> string(0) ""
["ich_konto_nr"]=> string(0) ""
["friend_vorname"]=> array(3) {
[0]=> string(0) ""
[1]=> string(0) ""
[2]=> string(0) ""
}
["friend_name"]=> array(3) {
[0]=> string(0) ""
[1]=> string(0) ""
[2]=> string(0) ""
}
["friend_strasse_nr"]=> array(3) {
[0]=> string(0) ""
[1]=> string(0) ""
[2]=> string(0) ""
}
["friend_plz_ort"]=> array(3) {
[0]=> string(0) ""
[1]=> string(0) ""
[2]=> string(0) ""
}
}
As you see there are some strings and some arrays. For the strings I am using the following code to find out if the value is set. If it is set, so I can use something like value="<?= $_SESSION['ich_vorname'] ?>"
.
$_SESSION['ich_vorname'] = (isset($_GET['ich_vorname']) && !empty($_GET['ich_vorname'])) ? $_GET['ich_vorname'] : 'error';
$_SESSION['ich_name'] = (isset($_GET['ich_name']) && !empty($_GET['ich_name'])) ? $_GET['ich_name'] : 'error';
$_SESSION['ich_strasse_nr'] = (isset($_GET['ich_strasse_nr']) && !empty($_GET['ich_strasse_nr'])) ? $_GET['ich_strasse_nr'] : 'error';
$_SESSION['ich_plz_ort'] = (isset($_GET['ich_plz_ort']) && !empty($_GET['ich_plz_ort'])) ? $_GET['ich_plz_ort'] : 'error';
$_SESSION['ich_email'] = (isset($_GET['ich_email']) && !empty($_GET['ich_email'])) ? $_GET['ich_email'] : 'error';
$_SESSION['ich_konto_nr'] = (isset($_GET['ich_konto_nr']) && !empty($_GET['ich_konto_nr'])) ? $_GET['ich_konto_nr'] : 'error';
The strings are not a problem but the arrays are! How can I set the value for the array fields when the fields are getting generated dynamically?