Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!