Is it possible to shorten this piece of PHP code?Honestly, I think it does not look clean but like a mess.if(Input::exists() && $token) {    if($validation->error('firstname') && $validation->error('lastname')) {        echo str_repeat(' ', 20), '<div class=addition error> You did not enter your name.</div>', \n;    } else if($validation->error('firstname')) {        echo str_repeat(' ', 20), '<div class=addition error> You did not enter your first name</div>', \n;    } else if($validation->error('lastname')) {        echo str_repeat(' ', 20), '<div class=addition error> You did not enter your last name.</div>', \n;    }}if(!Input::exists()) {        echo str_repeat(' ', 20), '<div class=addition> We will address you by this name.</div>', \n;}if(Input::exists() && $token) {    if($validation->error('emailConfirm') == 'match') {        echo str_repeat(' ', 20), '<div class=addition error> The email address you entered does not match.</div>', \n;    } else if($validation->error('emailConfirm') == 'type') {        echo str_repeat(' ', 20), '<div class=addition error> You did not re-enter a valid email address.</div>', \n;    } else if($validation->error('emailConfirm')) {        echo str_repeat(' ', 20), '<div class=addition error> You did not re-enter your email to confirm.</div>', \n;    }}else if(!Input::exists()) {        echo str_repeat(' ', 20), '<div class=addition> Re-enter your email to make sure it\'s correct.</div>', \n;    }
Shortening if-statements of displaying errors
php;validation
You are repeating the same code:echo str_repeat(' ', 20), '<div class=addition error> You did not enter your name.</div>', \n;Replace it with a function which will do the job:function message($content, $class = ''){    return str_repeat(' ', 20) . '<div' . (($class) ?  class='$class' : '') . >$content</div>\n;}You are using construction:if () {} else if() {}This is the same as: if () {} else { if() {} }I guess, that it is not what you want to use, the correct construction should be:if () {} elseif() {} The code itself can be rewritten like this:function message($content, $class = ''){    return str_repeat(' ', 20) . '<div' . (($class) ?  class='$class' : '') . >$content</div>\n;}if (!Input::exists()){    echo message('We will address you by this name.', 'addition');    echo message('Re-enter your email to make sure it\'s correct.', 'addition');} elseif (Input::exists() && $token) {    if($validation->error('firstname') && $validation->error('lastname')) {        echo message('You did not enter your name.', 'addition error');    } elseif($validation->error('firstname')) {        echo message('You did not enter your first name', 'addition error');    } else {        echo message('You did not enter your last name.', 'addition error');    }    if($validation->error('emailConfirm') == 'match') {        echo message('The email address you entered does not match.', 'addition error');    } elseif($validation->error('emailConfirm') == 'type') {        echo message('You did not re-enter a valid email address.', 'addition error');    } else {        echo message('You did not re-enter your email to confirm', 'addition error');    }}