0

In drupal 7: I have Answer content type and alter the form for that type:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'answer_node_form') {
    // disabling some fields (ie. #access title field to false)
    // setting defaults values
    // adding one hidden field (that shouldn't be inserted into database)
  }
}

A when I'm trying to submit edit form, the process of PHP takes too much time and Apache restarts. Do you have any idea what is wrong? Maybe when I send the form, it shouldn't have any additional fields?

I could paste the code but I think it's insignificant.

  • I think you cannot simply remove the title. Try setting some default values using form_alter – niksmac Jun 1 '12 at 11:26
  • Oh, I just hiding the title $form['title']['#access'] = false; so it is still sending via POST – kobylecki Jun 1 '12 at 11:29
1

As @NikhilMohan says, you can't just remove fields like the title; they're required for validation. Event setting #access => FALSE has strange results in my experience.

What you could do instead, is set a value for the fields you're hiding, and change their #type to 'value'. That way the element will still exist on the server side, and validation/submission won't break.

e.g.

$form['title']['#type'] = 'value';
$form['title']['#value'] = 'Some default value for the title';
  • OK, thanks for advice! I've implemented your solution, it is better, but my problem still exists. – kobylecki Jun 1 '12 at 11:39
  • OK, I've just figured it out that I should set #type to value in another field. And it helped. – kobylecki Jun 4 '12 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.