Laravel 4 - 表单拒绝显示除空白页面之外的任何内容

时间:2014-01-04 03:23:59

标签: php laravel laravel-4

好的,所以我在学习Laravel 4的同时在一个测试网站上工作。这是我的第一个MVC框架,所以我把它放慢了。

我已经实现了多项功能,包括:用户(通过Sentry),个人资料(用户更新自己的信息),以及所有这些功能正常。

现在,我正在开发一个允许用户请求服务报价的系统。我觉得我理解形式和处理输入背后的基本概念,但显然不是。我能够得到验证和所有的一切,所有这些都有效。但是现在,当我去实际执行操作时(一旦表单数据被验证),我就会不断给出一个空白页面。我已经尝试了很多东西。

这是我的QuoteController

public function create()
    {
        $user = Sentry::getUser();
        if(!isset($statusMessage)) $statusMessage = "";
        if(!isset($allErrors)) $allErrors = "";
        return View::make('quote.create')->with(array('user' => Sentry::getUser(), 'statusMessage' => $statusMessage, 'allErrors' => $allErrors));
    }
public function createDo()
    {
        $user = Sentry::getUser();
        $input = Input::all();
        $rules = array('quote_type' => 'required|in:web,design,other', 'budget' => 'required|in:1000,2000,5000,10000,20000,99999', 'sites_like' => 'max:5000', 'sites_dislike' => 'max:5000', 'content' => 'required|max:50000');
        $filesrules = array('file' => 'mimes:jpeg,png,pdf,doc,txt,bmp,gif|max:500');
        $validator = Validator::make($input, $rules);

if($validator->fails())
        {
            $allErrors = $validator->errors();
        }

        if(Input::hasFile('files'))
        {
            $files = Input::file('files');

            if (!is_array($files))
            {
                $files = array($files);
            }

            foreach($files as $file)
            {
                if (!is_a($file, 'Symfony\Component\HttpFoundation\File\UploadedFile')) {
                    continue;
                }

                $fileValidator = Validator::make(array('file' => $file), $filesrules);

                if($fileValidator->fails())
                {
                    $messages = $fileValidator->messages()->toArray();
                    foreach($messages['file'] as $message)
                    {
                        $allErrors->add('file', $message);
                    }
                }
            }
        }

        if($allErrors->any())
        {
            Input::flash();
            return Redirect::route('quote-create')->withErrors($allErrors)->withInput();
        }
        else
        {
                Quote::create(array(
                    'status' => 1,
                    'public_id' => strtoupper(substr(md5(rand(100000000,3888888888).time()), 0, 10)."-".substr(md5(rand(100000000,3888888888).time("a week ago")), 0, 10)),
                    'customer' => intval($user->id),
                    'quote_type' => $input['quote_type'],
                    'sites_like' => $input['sites_like'],
                    'sites_dislike' => $input['sites_dislike'],
                    'budget' => intval($input['budget']),
                    'content' => $input['content']));

            return Redirect::route('quote');
        }
    }

这是路线

// Quote
Route::get('/quote', array('before' => 'auth|quote', 'uses' => 'QuoteController@index', 'as' => 'quote'));
Route::post('/quote/create', array('uses' => 'QuoteController@createDo', 'as' => 'quote-createDo'));
Route::get('/quote/create', array('before' => 'auth', 'uses' => 'QuoteController@create', 'as' => 'quote-create'));


// Staff
Route::get('/staff', array('before' => 'auth.staff', 'uses' => 'StaffController@index', 'as' => 'staff-index'));


// Sandbox
Route::get('/sandbox', array('before' => 'permission:user.create', function()
{
    return "You have access!";
}));

最后,quote.create视图。

{{ $errors }}
{{ $statusMessage }}
<br/><br/>
{{ Form::open(array('route' => 'quote-createDo', 'files' => true)) }}
<br/><br/>
<label for="quote_type"><span>Type of Quote</span></label>
{{ Form::select('quote_type', array('web' => 'Web', 'design' => 'Design', 'other' => 'Other')) }}
<br/><br/>
<label for="budget"><span>Project Budget</span></label>
{{ Form::select('budget', array('1000' => 'Up to $1,000', '2000' => '$1,000 - $2,000', '5000' => '$2,000 - $5,000', '10000' => '$5,000 - $10,000', '20000' => '$10,000 - $20,000', '99999' => 'Over $20,000')) }}
<br/><br/>
<label for="sites_like"><span>Three designs you like</span>List three websites or designs that you like, and why - in regards to design, formatting, graphics, anything.  This will help us understand your tastes and give us a jumping-off point for your project.</label>
{{ Form::textarea('sites_like') }}
<br/><br/>
<label for="sites_dislike"><span>Three designs you don't like</span>Along the same lines, give us three examples of desgins or websites that you don't like.</label>
{{ Form::textarea('sites_dislike') }}
<br/><br/>
<label for="content"><span>The Meat</span>Explain to us, as best as you can, what you need us to do.</label>
{{ Form::textarea('content', '',array('class' => 'big')) }}
<br/><br/>
<label for="files[]"><span>File Upload</span>Upload any files here that might help us understand your needs better. (Diagrams, sketches, logos, etc.)</label>
{{ Form::file('files[]', array('multiple'=>true)) }}
<br/>
<br clear="all">
<br/><br/>
{{ Form::submit('Submit Quote', array('class' => 'submit')) }}
{{ Form::close() }}

非常感谢您的帮助!

0 个答案:

没有答案