2016-12-11 13 views
0

私はモーダルでニュースを登録したいと思いますが、問題は同じモーダルでエラーを検証したいときです。私はajaxをうまく処理しません。 エラーを表示するためにajaxで使用するコードを知りたいですか?私はlaravel 5.2のモーダルウィンドウを検証する方法

このコードは私のコードである

<!-- Modal --> 
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="z-index: 1300;"> 
    <div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
    <h4 class="modal-title" id="myModalLabel">Agregar Nueva Noticia</h4> 
    </div> 
    <div class="modal-body"> 
    {!! Form::open(['id' => 'form', 'files' => 'true']) !!} 

    <div class="form-group"> 
     {!! Form::label('title', 'Titulo') !!} 
     {!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Titulo de la Noticia..', 'riquired']) !!} 
    </div> 

    <div class="form-group"> 
     {!! Form::label('content', 'Agrega tu Noticia') !!} 
     {!! Form::textarea('content', null, ['class' => 'form-control textarea-content']) !!} 
    </div> 

    <div class="form-group"> 
     {!! Form::label('imagen', 'Agrega tu Imagen') !!} 
     {!! Form::file('photo', ['id' => 'photo']) !!} 
    </div> 

    <div class="form-group"> 
     <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button> 
     <button type="button" id="Guardar" class="btn btn-danger btn-sm">Guardar</button> 

    </div> 


{!! Form::close() !!} 

    </div> 
    <div class="modal-footer"> 

    </div> 
    </div> 
</div> 

Y MI controlador

public function store(NoticiaCreateRequest $request) 
{ 

//MANIPULACION DE IMAGENES 
if ($request->file('photo')) { 
    $file = $request->file('photo'); 
    $name = '/imagen/noticias/Cm' . time() . '.' . $file->getClientOriginalExtension(); 
    $path = public_path() . '/imagen/noticias/'; 
    $file->move($path, $name); 
} 

$datos = new Noticia(); 

$datos->title = $request->title; 
$datos->content = $request->content; 
$datos->photo = $name; 
$datos->save(); 

Session::flash('save', 'Se ha creado Correctamente'); 

return redirect()->route('admin.noticias.index'); 

     } 

YのMIは

 public function rules() 
    { 
return [ 

    'title' => 'min:8|max:65|required', 
    'content' => 'min:20|required', 
    'photo' => 'required', 
]; 

}

を要請

私が欲しいこの

enter image description hereのようなもの

+0

モーダルの代わりにiframeを使用します。 – Bugfixer

+0

iframeで動作するサンプルがありません –

+0

AJAXにあまり慣れていなくても、とにかくお勧めします。 Laravelは実装が非常に簡単です。いくつかのコードを試してください。問題が発生した場合はお手伝いします。 –

答えて

0

あなたがどうかを示す値「1」と名「fromModal」で「隠れた」入力タイプを渡し、モーダルてフォームを送信

enter image description hereフォームはモーダルから提出されました。モーダルを介して提出されない同様のフォームがある場合は、その 'hidden'入力タイプ値 '0'を保持します。

したがって、検証でエラーが発生すると、入力タイプ値もold()関数で受信され、old( 'fromModal')でアクセスできます。

この値が1の場合は、検証エラーを表示するには

$('#modal-CSS-Selector').modal('toggle'); 

とブートストラップモーダルを表示することができ、あなたが画像で述べたものと同様、Laravel Documentation for Validationで持っていてください。

関連する問題