You could perform a validation through get_blog_id_from_url($domain, $path)
function, assuming you are using directories and NOT subdomains. Otherwise, $path
is not required.
See code and comments below.
<?php
if ( ! empty( $_POST['sitename'] ) ) {
$main_site_url = network_site_url( "https://wordpress.stackexchange.com/" );
$domain = preg_replace( "/^https?:\/\/(www)?/", '', $main_site_url );
$path = preg_replace( "/\//", '', trim( $_POST['sitename'] ) );
$path = preg_replace( "/^(.+)$/", "/$1/", $path );
// If the sitename does not exist.
if ( ! $blog_id = get_blog_id_from_url( $domain, $path ) ) {
// Perform whatever you want here...
wp_die( 'Sitename does not exist.' );
} else {
wp_redirect( get_site_url( $blog_id ), 302 );
exit;
}
} ?>
<form name="linkform"
id="linkform"
method="post"
action="">
<p>
<label for="sitename">Site Name:</label>
<br><input type="text" name="sitename" id="sitename" value="" size="50"/>
</p>
<p class="submit">
<input id="submit" type="submit" name="Submit" class="submit" value="Go"/>
</p>
</form>
Put the PHP code plus the form HTML in the same place/page.