} else { var overlay = jQuery('<div id="contactFormResultsOverlay" class="boxOverlay"></div>').prependTo($("body")); overlay.fadeTo(0.001, 0); overlay.fadeTo("slow", 0.7); var results = jQuery('<div id="contactFormResults" class="boxBox"></div>').addClass('loading').prependTo($("body")); results.hide(); results.fadeIn("slow"); $.ajax({ url: "<?php echo URL::get('ajax', array('context' => 'submit_form')); ?> ", cache: false, data: {<?php $elements = AlienContact::elements(); $i = 0; foreach ($elements as $element) { $i++; echo $element['id']; ?> : $("#contactForm_<?php echo $element['id']; ?> ").val()<?php if ($i != count($elements)) { ?> , <?php } } ?>
/** * Fetch the form * * @param string $action where the form should be sent to (usually current URL) * @param string $input where input is coming from (only 'post' works now) * @return string the form */ public function get_form($action = '', $input = 'post') { $elements = self::elements(); $output = ''; $values = array(); $errors = array(); if ($input == 'post') { foreach ($elements as $key => $field) { if (isset($_POST['contactForm_' . $key]) || isset($_POST[$key])) { if (isset($_POST['contactForm_' . $key])) { $value = $_POST['contactForm_' . $key]; } else { $value = $_POST[$key]; } if (AlienContact::check_input($value, $key) != '') { $errors[$key] = AlienContact::check_input($value, $key); $values[$key] = $value; } else { $values[$key] = $value; } } } } else { foreach ($elements as $key => $field) { if (isset($input[$key])) { $value = $input[$key]; if (AlienContact::check_input($value, $key) != '') { $errors[$key] = AlienContact::check_input($value, $key); $values[$key] = $value; } else { $values[$key] = $value; } } } } if (count($errors) != 0) { $output .= '<div class="errors">'; $output .= '<h3>Errors</h3>'; $output .= '<ol>'; foreach ($errors as $id => $error) { $output .= '<li id="contactForm_' . $id . '_error"><a href="#contactForm_' . $id . '_div" title="Fix the error">' . $error . '</a>.</li>'; } $output .= '</ol>'; $output .= '</div>'; $output .= self::make_form($action, $values, $errors); } elseif (count($values) > 0) { if (self::submit($values)) { $output .= '<div class="success">'; $output .= '<h3>Success</h3>'; $output .= '<p>Your message has successfully been delivered.</p>'; $output .= '</div>'; } else { $output .= '<div class="errors">'; $output .= '<h3>Error</h3>'; $output .= '<p>Uh-oh... looks like I made a mistake. What can you expect? I am only a web server after all. Sorry... 1,000 times sorry. Please, give me another chance! I'm begging you! Will you ever talk to me again?'; $output .= '</div>'; $output .= self::make_form($action, $values, $errors); } } else { $output .= self::make_form($action, $values, $errors); } return $output; }