Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
How to execute form and after that onClick in Laravel

I want first to execute form and after that onClick(function) because the post form doesn't work.In this form if green button is submitted ,shows red button. After button is submitted I want to print hidden div. Thank you !

blade

 @foreach($movie->seats as $seat)
        <div id="printDiv" style="display:none;text-align:center">
            <h3 >Ред: 4</h3>
            <h3>Място: {{$seat->seat_id}}</h3>
            <h3>Филм: {{$movie->title}}<h3>
            <h3>Час: {{$movie->hour}}</h3>
            </div>
    @if($seat->reserved == 0)
    <form id="data" method="post" action="/seat/{{$seat->id}}">
        @csrf
        <button  type="submit"  onclick="printDiv('printDiv')" style="margin-left:10px; width:80px; display:inline;"  type="button" class="btn btn-success">{{$seat->seat_id}}</button>
        </form>
    @else
        <form  method="post" action="/destroy/{{$seat->id}}">
        @csrf
        
        <button type="submit"style="margin-left:10px; width:80px; display:inline;" type="button" class="btn btn-danger">{{$seat->seat_id}}</button>
        </form>
    @endif
    @endforeach

Script

function printDiv($idPage){
         
            var printContents = document.getElementById($idPage).innerHTML;
            var originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;

            window.print();
            document.body.innerHTML = originalContents;
        };

Controller

 public function changeReserved($id,Request $request){

        $request = Seats::find($id);
        $request->reserved = '1';
        $request->save();
     
        
        return redirect()->back();

        
    }
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda