예제 #1
0
            $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
예제 #2
0
/**
 * AJAX form responder
 * @param string $formId The HTML form ID
 * @param array $errors The array of the errors (it is used only for generic form processing)
 * @return void
 */
function form_respond($formId, $errors = null)
{
    Form::set('id', $formId);
    $errorStr = '';
    $ajaxResponse = true;
    form_set('error', validation_get('errors'));
    if (is_array($errors) && count($errors)) {
        Form::set('error', $errors);
        $ajaxResponse = false;
        # if no error message and no other message, no need to respond
        $message = Form::get('message');
        if (count(Form::get('error')) == 0 && empty($message)) {
            return;
        }
    }
    $response = array('formId' => Form::get('id'), 'success' => Form::get('success') ? true : false, 'error' => Form::get('error'), 'msg' => Form::get('message'), 'redirect' => Form::get('redirect'), 'callback' => Form::get('callback'));
    if ($ajaxResponse) {
        echo json_encode($response);
    } else {
        echo '<script type="text/javascript">';
        echo 'LC.Form.submitHandler(' . json_encode($response) . ')';
        echo '</script>';
    }
}
예제 #3
0
?>
</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');
                if (is_array($dimensions) && count($dimensions)) {
                    foreach ($dimensions as $d) {
                        $thumbFile = $uploadDir . $d . _DS_ . $post[$name];
                        if (is_file($thumbFile) && file_exists($thumbFile)) {
                            unlink($thumbFile);
                        }
                    }
                }
            }
        } else {
            $error = $file->getError();
            validation_addError($name, $error['message']);
        }
    }
    if (count(validation_get('errors'))) {
        $errors = validation_get('errors');
        # if there is any validation error and if there was any uploaded file
        $data['error'] = array('id' => $errors[0]['htmlID'], 'plain' => $errors[0]['msg'], 'html' => _msg($errors, 'error', 'html'));
        $data['value'] = $post[$name];
    }
    if (!$data['savedId'] && isset($post[$name . '-id']) && $post[$name . '-id']) {
        # if there was any saved data in db
        $data['savedId'] = $post[$name . '-id'];
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>AsyncFileUploader</title>
예제 #5
0
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');