Home › Ajax Response
Ajax Response
function my_color_ajax_response($form, &$form_state) { $color_entered = trim($form_state['values']['color']); $allowed_values = array('red','white','blue'); $message = '<div id="inner-message" class="'; $commands = array(); if (in_array($color_entered, $allowed_values)) { $myColor = new my_color(); $myColor->setName(trim($form_state['values']['color'])); $db= new dbMy_color(); try { $dbResult = $db->add($myColor); $message.='information">Your vote for '.$myColor->getName().' Processed Successfully.</div>'; $commands[] = ajax_command_css('#edit-color', array('background-color' => 'white')); $commands[] = ajax_command_css('#edit-color', array('border' => 'solid black 1px')); $commands[] = ajax_command_css('#message_area', array('class' => 'info')); } catch (Exception $e) { $message.='error">Error: An Unexpected Database Exception Occurred'; $commands[] = ajax_command_css('#message_area', array('class' => 'error'),array('class' => 'error')); } } else { $message.='error">Error: You have entered an invalid color</div>'; $commands[] = ajax_command_css('#edit-color', array('border' => 'solid red 1px')); $commands[] = ajax_command_css('#message_area', array('class' => 'error'),array('class' => 'error')); } $vars = _get_color_vote(); $commands[]=ajax_command_html('#message_area',$message ); $commands[] =ajax_command_html('#report_table', theme_table($vars)); return array('#type' => 'ajax', '#commands' => $commands); }



