By mockingbirdz on
Thank you for taking the time to look at this.
My module displays a form in a block. I perform some basic validations and set an error using form_set_error.
But the message displays in the wrong place (in the main content rather than next to the form in the block) . I have been searching for a solution to this problem for hours now but to no avail. Any idea what I am doing wrong?
This is the form
<form action="/drupal3/node/62" accept-charset="UTF-8" method="post" id="blockquiz-render-question-form">
<div>
<p>This is the question</p>
<div class="form-radios">
<div class="form-item" id="edit-tries-1-wrapper"> <label class="option" for="edit-tries-1"><input type="radio" id="edit-tries-1" name="tries" value="1" class="form-radio error" /> <span class="blockquiz_answer_text"><p>Answer 1</p> </span></label>
</div>
<div class="form-item" id="edit-tries-2-wrapper"> <label class="option" for="edit-tries-2"><input type="radio" id="edit-tries-2" name="tries" value="2" class="form-radio error" /> <span class="blockquiz_answer_text"><p>Answer 2</p>
</span></label>
</div>
<div class="form-item" id="edit-tries-3-wrapper"> <label class="option" for="edit-tries-3"><input type="radio" id="edit-tries-3" name="tries" value="3" class="form-radio error" /> <span class="blockquiz_answer_text"><p>Answer3</p>
</span></label>
</div>
</div><input type="hidden" name="qid" id="edit-qid" value="" />
<input type="submit" name="op" id="edit-submit" value="Answer Quiz" class="form-submit" />
<input type="hidden" name="form_build_id" id="form-f6a5cab0ce306b63e12dc45ab3deb8c2" value="form-f6a5cab0ce306b63e12dc45ab3deb8c2" />
<input type="hidden" name="form_token" id="edit-blockquiz-render-question-form-form-token" value="95ea6d5102d3e9cbc882bcad6a630675" />
<input type="hidden" name="form_id" id="edit-blockquiz-render-question-form" value="blockquiz_render_question_form" />
</div></form>
And this is the form_set_error code
if ($form_state['values']['tries'] == '')
form_set_error( 'tries', t('Your answer could not be recorded because you did not select any of the choices.'),TRUE);
Comments
What form_set_error()
What form_set_error() http://api.drupal.org/api/function/form_set_error/6 essentially does is to highlight the form element in question and set an error message in the messages area which is usually placed (by the theme's page template) at the top of the main page content. The message appears here so that you are sure to see it on page reload. So I think that what is happening is what is supposed to happen...
gpk
----
www.alexoria.co.uk
GPK is right - it's doing
GPK is right - it's doing what it's supposed to do. But, maybe this module can help you do what you want. I've never used it myself though, so I'm not sure how well it works.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks...
The Inline Messages module does exactly what I want... This is my first posting to the drupal forum and I am amazed at how quickly the responses came. Thank you GPK and Jay.
:-)
Well is is partly pot luck how quickly/whether you get a response but it does also depend on the question and how it is asked.!!
Glad you've found what you want anyway!
gpk
----
www.alexoria.co.uk