Look at the output of your code. It'll look like this:
<form action="http://www.example.com:80/login/" method=POSTonsubmit=return validate('user','pass');>
You should see the spacing problem, as well as the missing quotes around the method and onsubmit values.
You seem to split up then concatenate literal strings completely arbitrarily. Everything after $port can be inside a single set of quotes.
echo '<form action="' . $protocol . '://' . $_SERVER['HTTP_HOST'] . ':' . $port . '/login/" method="POST" onsubmit="return validate('user','pass');">';