Skip to content

Instantly share code, notes, and snippets.

@ounziw
Last active December 27, 2015 17:48
Show Gist options
  • Save ounziw/7364590 to your computer and use it in GitHub Desktop.
Save ounziw/7364590 to your computer and use it in GitHub Desktop.
Novius OS Form: view data you have entered, when you click next page link.
<?php
// put this file into local/views/apps/noviusos_form
// License: AGPL ver3.0 or later
$css = <<<EOS
dl.check_before_send dt {
float: left;
clear: left;
width: 200px;
}
dl.check_before_send dd {
float: left;
width: 200px;
}
EOS;
\Nos\Nos::main_controller()->addCssInline($css);
\Nos\Nos::main_controller()->addJavascript('static/apps/noviusos_templates_basic/js/jquery.js');
$js = <<<EOS
jQuery(function($) {
$('#form_submit').ready(function(){
$('.page_break').prepend('<dl class="check_before_send"><dt></dt><dd></dd></dl>');
});
$('.page_break_next').click(function(){
// clear data when going to new page.
// (without this, data will be duplicated at page 3 or later.)
$('dl.check_before_send>dt').remove();
$('dl.check_before_send>dd').remove();
// get form data
var fields = $("form").serializeArray();
// (for multiple choice)
// if 2 or more choices are checked, we will get the same formtitle with different values.
var formtitle_before = '';
var fieldvalue_before = '';
jQuery.each(fields, function(i, field){
// exclude form_captcha
if (field.name !== 'form_captcha') {
var formtitle = $('[name="'+field.name+'"]').attr('title');
var formtype = $('[name="'+field.name+'"]').attr('type');
// exclude hidden attribute data, and empty field
if (formtype !== 'hidden' && field.value) {
// compare formtitle of this field and the formtitle of the previous field.
// if formtitle is different, new dt-dd.
if (formtitle_before != formtitle) {
$(".check_before_send").append("<dt></dt><dd></dd>");
// the easist way of escaping before inserting is using text() method.
$(".check_before_send").find("dt:last").text(formtitle);
$(".check_before_send").find("dd:last").text(field.value);
} else {
// if formtitle is same, concatenates field.value.
// (for multiple choice)
field.value = fieldvalue_before + ', ' + field.value;
$(".check_before_send").find("dd:last").text(field.value);
}
// (for multiple choice)
formtitle_before = formtitle;
fieldvalue_before = field.value;
}
}
});
});
});
EOS;
\Nos\Nos::main_controller()->addJavascriptInline($js);
include APPPATH . 'applications/noviusos_form/views/foundation.view.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment