Hi
I need to implement validation check if the user has voted on the client side (show a msg & stop the form submission)
i know how to add onSumbit function to the form for validation (here is a sample- http://drupal.org/node/179994)

my question is how can i know the user has not voted yet ?

i see that there is a Select tag that is hidden and using the stars to votes does not change it
the only change i saw is that the star-N class was added a "on" class
i want my code to be genreic - so browsers that doesn't supports the widget , will work too

is that the way to check , or am i missing something here ?

Thanks Avior

Comments

avior’s picture

I will be happy is someone can give me a lead to start with

avior’s picture

this is what i did

on form_alter hook i have added

$form['#attributes']['onsubmit'] = 'return comment_cs_validate()';

i have added this function to the tpl file (in my case it was a view)

<script type="text/javascript">
      function comment_cs_validate() {
        if ($('#edit-vote-0-wrapper div div').hasClass("on")) {
          return true;
        } else {
          alert ('You must rank the story before submitting your post');
          return false;
        }
      }
      </script>  

i guess that there is a better way (a more genreric one)

rishi.kulshreshtha’s picture

I was also searching for some more generic way but didn't find yet, finally I've implemented this. For those who are still suffering from this can try this fix in their .module file.

/**
 * Implementation of hook_form_alter()
 */
function MODULE_form_alter(&$form, &$form_state, $form_id) { // Here replace your module name with "MODULE"
  // Log the $form_id to the watchdog
  // in this example, 'form_id' is just the log entry name. I commonly use 'wtf'
  watchdog('form_id', $form_id);

  if ($form_id == 'comment_form') {
    $form['#attributes']['onsubmit'] = 'return comment_cs_validate()';
  }
}
whiteph’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Sorry, Drupal 6 is end of life, and is no longer supported.