Make phone field required if certain shipping method is selected I use drupal 6 and ubercart 2. My aim is to make phone field in delivery address required if certain shipping method is selected. I have set up a jquery script that shows a message to the user saying that phone is needed after customer selects the shipping method. Despite of this, some customers don't fill out the phone field. 
I would like to add a non js check after submission of checkout page. 
I suppose I would need to write a small module. A need help with the start of the code

&lt;?php
IF 
{[mymethod] = true}
then {
  $form['panes']['delivery']['delivery_phone']['#required'] = true;
}
?&gt;


Thank you very much.

EDIT: according to @Adam Balsam answer I tried to make custom module
This is uc_checkout_phone.module

&lt;?php
function uc_checkout_phone_uc_cart_checkout_form_alter(&amp;$form, &amp;$form_state) {
  $form['panes']['delivery']['delivery_phone']['#element_validate'] = array('uc_checkout_phone_phone_validate');
}
function uc_checkout_phone_phone_validate($element, &amp;$form_state) {
  if (($form_state['panes']['shipping']['shipping_method']['#value'] == 'Doprava - kurier DPD') &amp;&amp; ($element['#value'] == '')) {
   form_error($element, t('You must enter a phone number if you select XXX as a shipping method.'));
 dpm($form_state); }
}
?&gt;


This is uc_checkout_phone.info

name = uc_checkout_phone
description = phone required
core = 6.x


The form id should be uc-cart-checkout-form. I had to write it using underscores. The shipping method is Doprava - kuriér DPD, I tried also the value which is flatrate_3---0 but I get no warning message if I let the phone number empty. Where can be the problem?
I named themodule: uc_checkout_phone
You will have two functions in your custom module. The first one is hook_form_FORM_ID_alter:

/**
 * This function adds an additional custom validation function to the delivery phone field
 *
 * Make sure you update MYMODULE and YOURFORMID to match your circumstances.
 */
function MYMODULE_form_YOURFORMID_alter(&amp;$form, &amp;$form_state) {
  $form['panes']['delivery']['delivery_phone']['#element_validate'] = array('MYMODULE_phone_validate');
}


The second function is the custom validation function that we added using hook_form_FORM_ID_alter above:

/**
 * Make sure you update MYMODULE again and update the array to match your shipping method
 */
function MYMODULE_phone_validate($element, &amp;$form_state) {
  if (($form_state['panes']['shipping']['shipping_method']['#value'] == 'THE SHIPPING METHOD') &amp;&amp; ($element['#value'] == '')) {
    form_error($element, t('You must enter a phone number if you select XXX as a shipping method.'));
  }
}