在发布之前检查页面是否正确填写

时间:2015-10-27 12:58:27

标签: php post

如果正确填写,我会尝试$_POST。此时它会在好的时候插入。但我需要在发布之前检查它是否正确。我不知道该怎么做..你们可以给我一个提示或告诉我该怎么做..

提前致谢。

if($_POST){

if( ! $sPageName = vad('pageName', $aPostClean)){
    throw new Exception('Invalid page name');
}

if( ! $sPageUrl = name2title($sPageName)){
    throw new Exception('Page name could not be made url safe');
}

if( ! $sParentPage = vad('parentId', $aPostClean)){
    throw new Exception('Invalid parent page');
}

$aParentPage = explode(',', $sParentPage);
if(count($aParentPage) != 2){
    throw new Exception('Invalid parent page');
}

$iParentId = $aParentPage[0];

if( ! $iParentId){
    $sUrl = '/'.$sPageUrl.'/';
}else{
    $sUrl = $aParentPage[1].$sPageUrl.'/';
}

if(vad('boolean_menu', $aPostClean) == 'true'){
    $bMenu = true;
}


$aPageData = $oControllerWizard->addPage(
    array(
        'name' => str_replace('/', '_', $aPostClean['pageName']),
        'url' => $sUrl,
        'type' => $iSelectedId,
        'in_menu' => $bMenu,
        'locked' => false,
    ),
    $iParentId
);

foreach($aPostClean as $k => $v){
    if(strpos($k, 'eav_') === 0){
        $sEavEntityName = str_replace('eav_', '', $k);

        $aEavCol = vad($sEavEntityName, $aEavCols);
        if( ! $aEavCol){
            continue;
        }

        $sTypeClass = get_type_class(vad('type', $aEavCol));
        if( ! $sTypeClass::validate($v, $oEavModel, $aEavCol)){
            $this->removePage($aPageData['id']);
            throw new Exception('Failed to validate eav column input');
        }

        $oControllerWizard->addEavValueByName($sEavEntityName, $aPageData['id'], $sTypeClass::save($v, $oEavModel, $aEavCol));
    }

    if(strpos($k, 'blocks_') === 0){
        $sBlockName = str_replace('blocks_', '', $k);

        $aBlockCol = vad($sBlockName, $aBlocksCols);
        if( ! $aBlockCol){
            continue;
        }

        $sTypeClass = get_type_class(vad('type', $aBlockCol));
        if( ! $sTypeClass::validate($v, $oBlocksModel, $aBlockCol)){
            $this->removePage($aPageData['id']);
            throw new Exception('Failed to validate block column input');
        }

        $oControllerWizard->addBlockValueByName($sBlockName, $aPageData['id'], $aPageData['framework_view_id'], $sTypeClass::save($v, $oBlocksModel, $aBlockCol));

    }
}

if($aPageData['framework_module_id']){
    $oCmsModuleSettings = new framework\base_model('cms_module_settings');
    $oCmsModuleSettings->setModuleIcon($aPostClean['input_moduleicon']);
    $oCmsModuleSettings->setDisplayName($aPostClean['display_name']);
    $oCmsModuleSettings->setModuleId($aPageData['framework_module_id']);
    $oCmsModuleSettings->setFkWebsites($iWebsiteId);
    $oCmsModuleSettings->save();
}

mess::col('Page has been added', true);
nav('/wizards/wizard/step-3/id:'.$iWebsiteId.'/');

}

1 个答案:

答案 0 :(得分:0)

我通常如何做到:

<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {

    $error = 0; // start of script so error = 0
    $errorMsg = Array(); // initiate error array

    if(empty($_POST['name'])) { // name = empty
        $error = 1; // set error to 1
        $errorMsg[] = "Bla bla bla error message"; // add message to array
    }
    if(empty($_POST['name1'])) { // name1 = empty
        $error = 1; // set error to 1
        $errorMsg[] = "Bla bla bla error message1"; // add message to array
    }

    if(!($error)) {
        // There is an error
        foreach($errorMsg as $msg) {
            echo $msg . "<br />";
            /* If both name and name1 were empty, it would output:
                    Bla bla bla error message
                    Bla Bla Bla error message1
            */
        }
    } else {
        // Everything was fine
        echo "SUCCES"
    }


}