表单未提交PHP操作

时间:2014-06-09 11:02:13

标签: php forms

我有以下聪明的tpl表格:

<form name="new_element" action="layout.php?action=newElement&pageId={$data.page.id}" method="POST">
    <input type="text" name="name" />
    <input type="submit" name="submit" />
</form>

layout.php动作如下所示:

<?php

    require_once('../initialize.php');

    $pages = new Smalllight($pdo, 'pages');
    $elements = new Smalllight($pdo, 'elements');
    $status = new Smalllight($pdo, 'status');
    $users = new SmalllightUsers($pdo, 'users');
    $profiles = new Smalllight($pdo, 'profiles');

    if($users->isLoggedIn() || $users->isRemember()) {
        //set user_id
        if(isset($_SESSION['user_id'])) { $user_id = $_SESSION['user_id']; }
        elseif(isset($_COOKIE['user_id'])) { $user_id = $_COOKIE['user_id']; }
        //reset Token
        if($users->isRemember()) { $users->resetToken($user_id, $settings['cookie_expire']); }

        //check if user is admin
        if($users->isAdmin()) {
            $data['admin'] = true;

            //find all statuses
            $getStatus = $status->findAll();
            if($getStatus == true) {
                foreach($getStatus as $status)
                { $data['status'][$status['id']] = $status; }
            }

            //-------------------//
            //----- ACTIONS -----//
            //-------------------//

            //----- VIEW LAYOUT -----\\
            if($_GET['action'] = 'viewLayout') {
                //find page
                $getPage = $pages->findById($_GET['pageId']);
                if($getPage == true) {
                    $data['page'] = $getPage;

                    //find page elements
                    $pageElements = $elements->findByFieldValue('page_id', $_GET['pageId']);
                    if($pageElements == true) {
                        $data['pageElements'] = $pageElements;
                    }

                    //find page elements with tree structure
                    $getElements = $elements->findTree(array('page_id' => $_GET['pageId']), null, array('position' => 'asc'));
                    if($getElements == true) {
                        $data['elements'] = $getElements;
                    }
                }

                //assign objects
                $smarty->assign('elements', $elements);
                //assign data and display
                $smarty->assign('data', $data);
                $smarty->assign('page', 'layout');
                $smarty->display('../themes/admin/layout.tpl');
            }

            echo '<pre>'; print_r($_POST); exit;

            //----- NEW ELEMENT ----\\
            if($_GET['action'] == 'newElement') {
                echo '<pre>'; print_r($_POST); exit;

                $elementCount = $elements->countByFieldValue('parent_id', $_POST['parent']);
                if($_POST['name'] != NULL) {
                    $elements->setValue('name', $_POST['name']);
                    $elements->setValue('type', $_POST['type']);
                    $elements->setValue('class', $_POST['class']);
                    $elements->setValue('style', $_POST['style']);
                    $elements->setValue('content', $_POST['content']);
                    $elements->setValue('parent_id', $parentId);
                    $elements->setValue('page_id', $_GET['pageId']);
                    $elements->setValue('status_id', $_POST['status']);
                    $elements->setValue('position', $elementCount++);
                    $elements->store();
                }
                header('Location: '.$settings['site_url'].'admin/layout.php?action=viewLayout&pageId='.$_GET['pageId']); exit;
            }
        }
        else { header('Location: '.$settings['site_url'].'index.php'); exit; }
    }
    else { header('Location: '.$settings['site_url'].'index.php'); exit; }

?>

正如您所看到的,我已将echo '<pre>'; print_r($_POST); exit;设置为操作的第一行,但是当我提交表单时,它只会将我带到表单必须去的位置(此处:layout.php) ?action = newElement&amp; pageId = 328)并且什么都不做。

我有另一个名为pages.php的文件,它具有完全相似的功能,并且有效。

0 个答案:

没有答案