So I have an input form where the user would enter a username, after submitting, the site would gather information based on the username, however, if there is a space within the username, the username becomes void (non-existant). How would I add a behaviour in PHP that rids of any and all spaces, so that instead of the final submitted username being john doe
, it would be johndoe
.
Here's my form code:
<form action="php.php" method="GET">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Enter username" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
And here's the php.php
file code:
//I GUESS THIS IS WHERE THE TRIMMING SHOULD HAPPEN?
<?php
//error_reporting(E_ALL & ~E_NOTICE);
// Load the username from somewhere
if (
$username = $_GET["username"]
) {
//do nothing
} else {
//$username = "notch";
echo "Oops! Something went wrong!";
}
?>