You're welcome, it's just a matter of debugging it right. You'll get more experienced the more you try to.
The print_r will just output the array in a readable format. It's a method to bebug, see it somethings there. You can remove it.
The alternative : is for if and foreach's in php you can do this to wrap instead of the curly brackets {}. It's easier if you're mixing html and php and instead of the closing } you write "endif;" or "endforeach;" - If you want an else in a if condition you write "else:".
<?php foreach($a as $<img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> : ?>
<p><?php echo $b</p>
<?php endforeach; ?>
<?php if($a == $<img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> : ?>
<p><?php echo $b</p>
<?php else: ?>
<p>not same</p>
<?php endif; ?>
I moved the main php logic of the form to the top. This because I like it to have this way from top to bottom logic. I'm not saying you abolutely should do it that way, but for me it looks littler cleaner. There's also different approaches. (I'm sure diogo will post something else

)
This way I have set a $success var to be false and wrap the form into the if(!$success): and also print any errors before the form. And then in the else: of the if(!$success) is true have the success message printed and the form will not be shown.