Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
button form for header sticky by javascript html laravel

There are two buttons on that blades (Laravel). The button (.btn-main) works in the main, but the button (.btn-header) in the header does not work.

I mean when i click the button (.btn-header) in the header, it does nothing and does not save in the database.

I know it is about the form.

inc/header.blade.php

<div class="sticky fixed">
<button type="submit" class="btn-header">Save</button>
</div>

index.blade.php

@extends('layouts.app')
@section('content')
<main>
<form action="{{ route('post.update', $post->id) }}" method="POST">
    @method('PUT')
    @csrf
    <input type="text" name="title" value="Title...">
    <input type="text" name="content" value="This is a test.">
    <button type="submit" class="btn-main">Save</button>
</form>
</div>
@endsection

app.blade.php

<!DOCTYPE html>
<html>
<head>...</head>
<body>
<header>
@include('inc.header')
</header>
@yield('content')
</body>
</html>

I want the buttons to work on both sections (header and main) and store the information in the database.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your header button doesn't do anything because it is not part of/inside the form. You can however use a form attribute for your header button to work. Add an id attribute to your <form> element and point the form attribute in your button to that same id.

Your form:

@extends('layouts.app')
@section('content')
<main>
<form action="{{ route('post.update', $post->id) }}" method="POST" id="myForm">
    @method('PUT')
    @csrf
    <input type="text" name="title" value="Title...">
    <input type="text" name="content" value="This is a test.">
    <button type="submit" class="btn-main">Save</button>
</form>
</div>
@endsection

(Added id="myForm" to the <form> element.)

Your header button:

<div class="sticky fixed">
<button type="submit" class="btn-header" form="myForm">Save</button>
</div>

(Added form="myForm" to the button.)

Edit: make sure there is no other id="myForm" on your page, choose a different unique name if so

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda