I've adapted the poll module (drupal 5) into a custom node module that allows the addition of multiple rows to my node. What I'd like to do is, on edit of the node hide the submit button until the "preview" button has been pressed (which effectively adds any additional rows desired, and "commits" any changes made) after which the submit button will then be visible. I figured since the submit and preview buttons are generated by default for a node input form I should use hook_form_alter to alter these elements. I'm trying to use form_alter to add a class of "hidden" to submit when in pre-preview and "nothidden" when in post-preview. However, I'm having trouble getting a condition where this triggers. What I have now is like this:

function my_form_alter($form_id, &$form) {
  if ($form['#attributes']['class'] == 'my_form' && arg(2) == 'edit' && [some conditional pre-preview]) {
    $form['submit']['#attributes'] = array('class' => 'hidden')
}
  elseif ($form['#attributes']['class'] == 'my_form' && arg(2) == 'edit' && [some conditional post-preview]) {
    $form['submit']['#attributes'] = array('class' => 'nothidden')
}
}

Any suggestions on how to write this conditional?

Comments

mjlF95’s picture

I'm able to use if (isset($form_values)) or if (!isset($form_values)) inside my form function but if I try to use it in this form_alter it doesn't work.

Is there a way to get it to work like passing it $form_values or something?

Note: I tried passing $form_values to this function but it complains it's undefined (pretty much makes sense). I'm using another function that I copy pasted from a thread I don't have the link to right now that does "global $form_vaules" and then starts working on $form_values.

Example:

function my_node_form_add_preview($form){
  global $form_values;
  if($form_values['op'] == t('Accept Edited Values')){
    $form_values['op'] = t('Preview');
    $form = node_form_add_preview($form);
    $form_values['op'] = t('Accept Edited Values'); //Don't want node_form_add_preview invoked again. 
  }

I tried adding global $form_values; to the form_alter function and then var_dumping $form_values but it comes up as array(0) { }, or sometimes array(0) { } NULL but I don't seem to be able to catch a state during pre-preview or post-preview like you can with if (isset($form_values)) or if (!isset($form_values)) in the form function.