Skip to content
PHP Logo

How can PHP be used to extract URL parameters for prefilling input fields?

To extract URL parameters in PHP for prefilling input fields, you can use the $_GET superglobal array. This array contains key-value pairs of parameters passed in the URL. You can then use these parameters to prefill input fields on a form by echoing the parameter values within the input field's value attribute.

php
<input type="text" name="username" value="<?php echo isset($_GET['username']) ? $_GET['username'] : ''; ?>">
<input type="email" name="email" value="<?php echo isset($_GET['email']) ? $_GET['email'] : ''; ?>">
<input type="password" name="password" value="">