【问题标题】:Saving data from form in db, Silverstripe将表单中的数据保存在 db, Silverstripe
【发布时间】:2017-01-07 00:26:31
【问题描述】:

我需要在 SilverStripe 中将一些数据从表单传递到数据库,但是当我单击“发送”按钮时,我得到的只是重新加载带有空白字段的表单,当然 db 中没有数据。下面是表单文件的代码(这里太长粘贴成代码标签了):http://pastebin.com/KHnZug9Z

这就是 DataObject 文件的样子:

/**
 * Class MonthlyReviewRequest
 */

class MonthlyReviewRequest extends DataObject {

    protected $controller;
    protected $record;

    private static $db = array(
        'NameAndSpecialisation' => 'Varchar(255)',
        'MBRDate'               => 'Date',
        'PredictionCompaniesAdded'        => 'Int',
        'PredictionManagersAdded'         => 'Int',
        'PredictionCandidatesAdded'       => 'Int',
        'PredictionSendoutsDone'          => 'Int',
        'PredictionLivejobsPerm_Con'      => 'Int',
        'PredictionMailshotsDone'         => 'Int',
        'Prediction1stInterview'          => 'Int',
        'Prediction2ndInterview'          => 'Int',
        'PredictionAddsAdded'             => 'Int',
        'PredictionMeetingsAdded'         => 'Int',
        'PredictionProjectPlanSendSigned' => 'Int',
        'PredictionRetainer1'             => 'Text',
        'PredictionRetainer2'             => 'Text',
        'PredictionDealsAddedPermCon'     => 'Int',

        'ActualCompaniesAdded'        => 'Int',
        'ActualManagersAdded'         => 'Int',
        'ActualCandidatesAdded'       => 'Int',
        'ActualSendoutsDone'          => 'Int',
        'ActualLivejobsPerm_Con'      => 'Int',
        'ActualMailshotsDone'         => 'Int',
        'Actual1stInterview'          => 'Int',
        'Actual2ndInterview'          => 'Int',
        'ActualAddsAdded'             => 'Int',
        'ActualMeetingsAdded'         => 'Int',
        'ActualProjectPlanSendSigned' => 'Int',
        'ActualRetainer1'             => 'Text',
        'ActualRetainer2'             => 'Text',
        'ActualDealsAddedPermCon'     => 'Int',

        'PipelinePermJob' => 'Text',
        'PipelinePerm1stInt' => 'Int',
        'PipelinePermStatus' => 'Text',

        'PipelineConJob' => 'Text',
        'PipelineCon1stInt' => 'Int',
        'PipelineConStatus' => 'Text',

        'ActionPlan'            => 'Text',
        'PromotionTarget'       => 'Float',
        'Leadership'            => 'Text',
        'DevelopmentPoints'     => 'Text',
        'TrainingAndHelp'       => 'Text',
        'OtherPoints'           => 'Text'
    );

    private static $has_one = array(
        'Page' => 'Page'
    );

    /**
     * @param bool $includerelations
     * @return array|string
     */
    public function fieldLabels($includerelations = true) {

        $labels = parent::fieldLabels();

        $labels['NameAndSpecialisation']        = _t('MonthlyReviewRequest.NameAndSpecialisation', "Name and specialisation:");
        $labels['MBRDate']                      = _t('MonthlyReviewRequest.MBRDate', "MBR Date:");

        $labels['PredictionCompaniesAdded']               = _t('MonthlyReviewRequest.PredictionCompaniesAdded', "Companies added:");
        $labels['PredictionManagersAdded']                = _t('MonthlyReviewRequest.PredictionManagersAdded', "Managers added:");
        $labels['PredictionCandidatesAdded']              = _t('MonthlyReviewRequest.PredictionCandidatesAdded', "Candidates added:");
        $labels['PredictionSendoutsDone']                 = _t('MonthlyReviewRequest.PredictionSendoutsDone', "Sendouts done:");
        $labels['PredictionLivejobsPerm_Con']             = _t('MonthlyReviewRequest.PredictionLivejobsPerm_Con', "Livejobs Perm/Con:");
        $labels['PredictionMailshotsDone']                = _t('MonthlyReviewRequest.PredictionMailshotsDone', "Mailshots done:");
        $labels['Prediction1stInterview']                 = _t('MonthlyReviewRequest.Prediction1stInterview', "1st Interview:");
        $labels['Prediction2ndInterview']                 = _t('MonthlyReviewRequest.Prediction2ndInterview', "2nd Interview:");
        $labels['PredictionAddsAdded']                    = _t('MonthlyReviewRequest.PredictionAddsAdded', "Adds added:");
        $labels['PredictionMeetingsAdded']                = _t('MonthlyReviewRequest.PredictionMeetingsAdded', "Meetings added:");
        $labels['PredictionProjectPlanSendSigned']        = _t('MonthlyReviewRequest.PredictionProjectPlanSendSigned', "Project plans send / signed:");
        $labels['PredictionRetainer1']                    = _t('MonthlyReviewRequest.PredictionRetainer1', "Retainer 1:");
        $labels['PredictionRetainer2']                    = _t('MonthlyReviewRequest.PredictionRetainer2', "Retainer 2:");
        $labels['PredictionDealsAddedPermCon']            = _t('MonthlyReviewRequest.PredictionDealsAddedPermCon', "Deals added Perm / Con:");

        $labels['ActualCompaniesAdded']               = _t('MonthlyReviewRequest.ActualCompaniesAdded', "Companies added:");
        $labels['ActualManagersAdded']                = _t('MonthlyReviewRequest.ActualManagersAdded', "Managers added:");
        $labels['ActualCandidatesAdded']              = _t('MonthlyReviewRequest.ActualCandidatesAdded', "Candidates added:");
        $labels['ActualSendoutsDone']                 = _t('MonthlyReviewRequest.ActualSendoutsDone', "Sendouts done:");
        $labels['ActualLivejobsPerm_Con']             = _t('MonthlyReviewRequest.ActualLivejobsPerm_Con', "Livejobs Perm/Con:");
        $labels['ActualMailshotsDone']                = _t('MonthlyReviewRequest.ActualMilshotsDone', "Mailshots done:");
        $labels['Actual1stInterview']                 = _t('MonthlyReviewRequest.Actual1stInterview', "1st Interview:");
        $labels['Actual2ndInterview']                 = _t('MonthlyReviewRequest.Actual2ndInterview', "2nd Interview:");
        $labels['ActualAddsAdded']                    = _t('MonthlyReviewRequest.ActualAddsAdded', "Adds added:");
        $labels['ActualMeetingsAdded']                = _t('MonthlyReviewRequest.ActualMeetingsAdded', "Meetings added:");
        $labels['ActualProjectPlanSendSigned']        = _t('MonthlyReviewRequest.ActualProjectPlanSendSigned', "Project plans send / signed:");
        $labels['ActualRetainer1']                    = _t('MonthlyReviewRequest.ActualRetainer1', "Retainer 1:");
        $labels['ActualRetainer2']                    = _t('MonthlyReviewRequest.ActualRetainer2', "Retainer 2:");
        $labels['ActualDealsAddedPermCon']            = _t('MonthlyReviewRequest.ActualDealsAddedPermCon', "Deals added Perm / Con:");

        $labels['PipelinePermJob']            = _t('MonthlyReviewRequest.PipelinePermJob', "Job");
        $labels['PipelinePerm1stInt']            = _t('MonthlyReviewRequest.PipelinePerm1stInt', "No. of 1st Int");
        $labels['PipelinePermStatus']            = _t('MonthlyReviewRequest.PipelinePermStatus', "Status");

        $labels['PipelineConJob']            = _t('MonthlyReviewRequest.PipelineConJob', "Job");
        $labels['PipelineCon1stIn']            = _t('MonthlyReviewRequest.PipelineCon1stIn', "No. of 1st Int");
        $labels['PipelineConStatus']            = _t('MonthlyReviewRequest.PipelineConStatus', "Status");

        $labels['ActionPlan']        = _t('MonthlyReviewRequest.ActionPlan', "Action Plan:");

        $labels['PromotionTarget']        = _t('MonthlyReviewRequest.PromotionTarget', "Promotion Target:");
        $labels['Leadership']             = _t('MonthlyReviewRequest.Leadership', "Leadership:");
        $labels['DevelopmentPoints']      = _t('MonthlyReviewRequest.DevelopmentPoints', "Development Points:");
        $labels['TrainingAndHelp']        = _t('MonthlyReviewRequest.TrainingAndHelp', "Training & Help:");
        $labels['OtherPoints']            = _t('MonthlyReviewRequest.OtherPoints', "Other Points");

        $labels['SaveReviewForm'] = _t('MonthlyReviewRequest.SaveReviewForm', "Submit Review");

        return $labels;
    }

    public function sendMonthlyReviewRequestToSireEmail()
    {        
        FrontendEmail::create()->sendMonthlyReviewRequestToSireEmail($this, MonthlyReviewRequest $monthlyreviewrequest, ContentController $controller);
    }

    public function providePermissions()
    {
        return array(
            "VIEW_MONTHLY_REVIEW" => "View Monthly Review",
        );
    }
}

还有第三个文件,它创建一个 CRM 菜单并从此菜单重定向到表单:http://pastebin.com/BCu4dtw3

哪里出错了?我整天都在与这个错误作斗争......

【问题讨论】:

    标签: php database forms crm silverstripe


    【解决方案1】:

    FormAction 的第一个参数应指定应在提交时处理表单的控制器函数。

    在您的代码中,您的FormAction 操作设置为saveReviewFormsaveReviewForm 必须是控制器上的函数,而不是表单上的函数。

    还要注意您的 getCustomFormActions 函数错误地将 FormAction 操作设置为 'MonthlyReviewRequest.SubmitReview'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多