How to check if the user is guest in a form
Can you please elaborate the question. As per the understanding you have to  use this condition to check the user login status.
Since you have to use it in a form, you can implements with hook_form_FORM_ID_alter().  

Use this code to check.

if (user_is_logged_in()) {
    echo "Logged In";
}
else {
    echo "Not logged in";
}


Edited:

Example for user_profile_form alter. 
FORM_ID = user_profile_form

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_user_profile_form_alter(&amp;$form, &amp;$form_state, $form_id) {
}


To find form id add this in your custom module.

/**
 * Implements hook_form_alter().
 */ 
function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  print_r($form_id);
}


When you visit the page the form is on, the form_id  will be displayed.

print_r($form); , you can see all details of a form, like form ID, field names of a form etc.

Also you can inspect the form and find the form id

&lt;form enctype="multipart/form-data" action="/user/288/edit" method="post" id="user-profile-form" accept-charset="UTF-8"&gt;


Here id="user-profile-form",
 in order to use it in code replace hiphen (-) with undescore(_)

 user-profile-form =&gt; user_profile_form