How can a PHP developer create a select-box form for link redirection with target blank without using JavaScript?
To create a select-box form for link redirection with target blank without using JavaScript, the PHP developer can use the `header()` function to redirect the user to the selected URL with the `target="_blank"` attribute. The form will submit to the same PHP page, and based on the selected option, the PHP code will redirect the user to the chosen URL with `target="_blank"`.
<?php
if(isset($_POST['url'])){
$selectedUrl = $_POST['url'];
header("Location: $selectedUrl");
exit();
}
?>
<form method="post">
<select name="url">
<option value="https://www.example.com" selected>Example</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.github.com">GitHub</option>
</select>
<input type="submit" value="Go" />
</form>
Related questions
-
require_once classes PHP files
-
Contao images directory path
-
PHP UDP listening socket