I have a form and I need a way of ensuring that only people with a particular email address can successfully signup. For example the only users allowed are from foo.com, so every email address should be like myemail@foo.com. Now I want the user to only have to enter the email user name and after the form is submitted I add the @foo.com using php. How would I go about implementing such a feature and if there is a better way to achieve the desired result where can I find such information . Thanks.
Easy, name the form field username for example. Name your submit button submit for example
then on form submit
if(isset($_POST['submit'])){
$username = $_POST['username'];
$username .= "@foo.com" // jacksperro@foo.com
// rest of your code
}
On a note, I'd put a label after the input box saying '@foo.com' to let them know to only type their username
This is basic string concatenation.
$suffix = '@foo.com';
$username = 'test';
$email = $username . $suffix;
Try this, it should do what you need and more:
<?php
if(isset($_POST['submit'])){
$user = trim(htmlspecialchars($_POST['username'])); // a bit of security
$final_user = sprintf("%s@foo.com", $user); // user@foo.com
echo $final_user;
}
?>