manipulate form variables before render() I have the following line of code in a user-profile-form.tpl.php which Drupal uses to render an input field in the user's edit profile page.

print render($form['field_machine_name']);
// this field can be found in the database table field_data_field_machine_name


The issue is that I want to run the value field_machine_name through a function like $form['field_machine_name'] = make_seo_url($form['field_machine_name']) before I run the render() function.  But this totally breaks the form because $form['field_machine_name'] is some very large array and render() output html input tag instead of the actual field_machine_name itself.

How does one actually go about massaging values in the $form variable before outputting it as an html field in render()?

Additionally, i want to make sure anytime field_machine_name is printed anywhere on the drupal site, i want it to run through the make_seo_url() function.  Is there a global place i can do this?
The Form API has #pre_render per element. You can use hook_form_alter to add your pre-render function to the list of functions that need to be called to show the value.


  #pre_render
  
  Used by: All elements and forms.
  
  Description: Function(s) to call before rendering in drupal_render()
  has occured. The function(s) provided in #pre_render receive the
  element as an argument and must return the altered element.
  
  Values: An array of function names to call.
  
  Note: If you are altering an existing form via hook_form_alter() or a
  similar means, be careful with this property! As demonstrated here,
  you will probably want to add to the existing array rather than
  writing over it.


I recommend being careful of when your module runs when trying to interact with Forms, Ajax, etc (your modules' weight). If needed I also recommend seeing hook_module_implements_alter if you want to adjust when your hook is called, without affecting your modules' weight.