$post['sheet-dir'] = The directory where the file(s) are saved, encoded by base64_encode() $post['sheet-fileName'] = The same value of $post['sheet'] */ ### The following commented section works with the sample database ### /* if (isset($post['photo-postId']) && $post['photo-postId']) { # Save file name in db # This is only needed when `onUpload` callback is not provided in view.php db_insert('post_image', array( 'pimgFileName' => $post['photo'], 'postId' => $post['photo-postId'] ), $useSlug=false); } # Save file name in db # This is only needed when `onUpload` callback is not provided in view.php db_insert('document', array( 'docFileName' => $post['doc'], ), $useSlug=false); */ $success = true; if ($success) { form_set('success', true); form_set('callback', 'postOutput(' . json_encode($post) . ')'); } } else { form_set('error', validation_get('errors')); } } form_respond('frmAsynFileUpload'); # Ajax response
/** Form validation prerequites here, for example *** $validations = array( 'txtTitle' => array( 'caption' => _t('Title'), 'value' => $txtTitle, 'rules' => array('mandatory'), ), 'txtBody' => array( 'caption' => _t('Body'), 'value' => $txtBody, 'rules' => array('mandatory'), ), ); */ $validations = array(); if (form_validate($validations)) { /** Database operations here */ if ($success) { form_set('success', true); form_set('redirect', _url('home')); } } else { form_set('error', validation_get('errors')); } } form_respond('formID'); # Ajax response
$args = array(); $user = db_select('user', 'u')->where()->condition('LOWER(username)', strtolower($txtUsername))->getSingleResult(); if ($user) { if ($user->username === 'admin' && $user->isMaster || $user->password && $user->password == _encrypt($txtPwd)) { $success = true; unset($user->password); # Create the Authentication object auth_create($user->uid, $user); } else { # Other follow-up errors checkup (if any) validation_addError('Password', _t('Password does not match.')); $error = true; } } else { # Other follow-up errors checkup (if any) validation_addError('Username', 'Username does not exists.'); $error = true; } if ($error) { form_set('error', validation_get('errors')); } if ($success) { form_set('success', true); form_set('redirect', _url('admin/post')); } } else { form_set('error', validation_get('errors')); } } form_respond('frmLogin'); # Ajax response
<?php /** * The action.php (optional) handles form submission. * It should perform form validation, create, update, delete of data manipulation to database. * By default, a form is initiated for AJAX and action.php is automatically invoked if the action attribute is not given in the <form> tag. */ _cfg('layoutMode', true); # Normally this is not needed here if you configured it in /inc/config.php $success = false; if (sizeof($_POST)) { $post = _post($_POST); extract($post); $validations = array('txtName' => array('caption' => _t('Name'), 'value' => $txtName, 'rules' => array('mandatory')), 'txtEmail' => array('caption' => _t('Email'), 'value' => $txtEmail, 'rules' => array('mandatory', 'email')), 'txtConfirmEmail' => array('caption' => _t('Re-type Email'), 'value' => $txtConfirmEmail, 'rules' => array('mandatory', 'email', 'validate_emailRetyped'), 'parameters' => array('validate_emailRetyped' => array($txtEmail)), 'messages' => array('mandatory' => _t('Please re-type Email.'), 'validate_emailRetyped' => _t('Your re-typed email address does not match.'))), 'txaComment' => array('caption' => _t('Comment'), 'value' => $txaComment, 'rules' => array('mandatory'))); if (form_validate($validations)) { /** Database operations here */ $success = true; if ($success) { form_set('success', true); form_set('message', _t('Your comment has been posted.')); } } else { form_set('error', validation_get('errors')); } } form_respond('frmComment'); # Ajax response
$validations = array('txtFullName' => array('caption' => _t('Full Name'), 'value' => $txtFullName, 'rules' => array('mandatory')), 'txtUsername' => array('caption' => _t('Username'), 'value' => $txtUsername, 'rules' => array('mandatory', 'username', 'validate_checkDuplicateUsername'), 'parameters' => array($hidEditId), 'messages' => array('validate_checkDuplicateUsername' => _t('Username already exists. Please try another one.'))), 'txtEmail' => array('caption' => _t('Email'), 'value' => $txtEmail, 'rules' => array('mandatory', 'email'))); if (!$hidEditId) { $validations['txtPwd'] = array('caption' => _t('Password'), 'value' => $txtPwd, 'rules' => array('mandatory', 'minLength', 'maxLength'), 'min' => 8, 'max' => 20); $validations['txtConfirmPwd'] = array('caption' => _t('Confirm Password'), 'value' => $txtConfirmPwd, 'rules' => array('mandatory', 'validate_confirmPassword'), 'parameters' => array($txtPwd), 'messages' => array('validate_confirmPassword' => _t('"%s" does not match.'))); } if (form_validate($validations)) { if ($hidEditId) { $data = array('uid' => $hidEditId, 'fullName' => $txtFullName, 'username' => $txtUsername, 'email' => $txtEmail, 'role' => $cboRole); if (!empty($txtPwd)) { $data['password'] = $txtPwd; } if (db_update('user', $data)) { $success = true; } } else { $auth = $_auth; $data = array('fullName' => $txtFullName, 'username' => $txtUsername, 'email' => $txtEmail, 'password' => _encrypt($txtPwd), 'role' => $cboRole); if (db_insert('user', $data)) { $success = true; } } if ($success) { form_set('success', true); form_set('redirect', _url('admin/user/list')); } } else { form_set('error', validation_get('errors')); } } form_respond('frmUser');
} else { # NEW/EDIT $validations = array('txtName' => array('caption' => _t('Name') . ' (' . _langName($lc_defaultLang) . ')', 'value' => $txtName, 'rules' => array('mandatory'), 'parameters' => array($hidEditId))); if (form_validate($validations)) { if ($hidEditId) { $data = array('catId' => $hidEditId, 'catName' => $txtName); # Get translation strings for "catName" $data = array_merge($data, _postTranslationStrings($post, array('catName' => 'txtName'))); if (db_update('category', $data, false)) { $success = true; } } else { $data = array('catName' => $txtName); # Get translation strings for "pptName" $data = array_merge($data, _postTranslationStrings($post, array('catName' => 'txtName'))); if (db_insert('category', $data)) { $success = true; } } } else { form_set('error', validation_get('errors')); } } if ($success) { form_set('success', true); form_set('callback', 'LC.Page.Category.list()'); # Ajax callback } } form_respond('frmCategory'); # Ajax response
?> </h3> <p>This is an example page which shows generic file upload handling.</p> <p> <form id="frmUpload" method="post" class="no-ajax" enctype="multipart/form-data"> <?php echo flash_get('file-upload-success'); ?> <div class="message"></div> <div class="table"> <div class="row"> <input type="file" name="filImage" id="filImage" /> </div> <div class="row"> <input type="submit" name="btnUpload" value="<?php echo _t('Upload'); ?> " class="button green" /> </div> </div> <?php form_token(); ?> </form> <?php form_respond('frmUpload', validation_get('errors')); ?> </p> <?php include _i('inc/tpl/footer.php');
echo _t('Re-type your email *'); ?> " /> </div> <div class="row"> <textarea name="txaComment" rows="7" cols="60" placeholder="<?php echo _t('Enter comment *'); ?> "><?php echo form_value('txaComment'); ?> </textarea> </div> <div class="row"> <input type="submit" name="btnSubmit" value="<?php echo _t('Post Comment'); ?> " class="button green" /> </div> </div> <?php form_token(); ?> </form> <?php form_respond('frmComment', validation_get('errors')); ?> </p> <?php include _i('inc/tpl/footer.php');