Reload url with variable from form field PHP/HTML/Javascript - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, October 4, 2022

Reload url with variable from form field PHP/HTML/Javascript

I want to pass variable into url after language is selected and page reloaded so it looks like this:

http://localhost/car.php?generation=value

However when page reloads my url looks like this:

http://localhost/car.php?generation=

How can I reload page and pass variable into url?

I am using this for php which reloads page:

if(isset($_GET['lang']) && !empty($_GET['lang'])){
 $_SESSION['lang'] = $_GET['lang'];
 header('Location: car.php?generation='.$_GET['generation'].'');
}

This is for language change:

<body>
 <script>
 function changeLang(){
  document.getElementById('form_lang').submit();
 }
 </script>

 <form method='GET' action='car.php?generation=<?php echo $_GET['generation']; ?>'   id='form_lang' >
   Select Language : <select name='lang' onchange='changeLang();' >
   <option value='en' <?php if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'en'){ echo "selected"; } ?> >English</option>
   <option value='sk' <?php if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'sk'){ echo "selected"; } ?> >Slovak</option>
  </select>
 </form>


source https://stackoverflow.com/questions/73939319/reload-url-with-variable-from-form-field-php-html-javascript

No comments:

Post a Comment