Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 426
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: January 15, 20252025-01-15T19:54:53+00:00 2025-01-15T19:54:53+00:00In: PHP

php – When I click submit the data is not sent and continues to be directed back to post/create and there is no error message

  • 0
  • 0
php – When I click submit the data is not sent and continues to be directed back to post/create and there is no error message

Previously my create data module was running and there was no error, but when I added a new module, my store function couldn’t be used and I don’t know what the cause was because there was no error message in my console

here is my controller

     [
            'user' => [
                'name' => Auth::user()->name,
                'email' => Auth::user()->email,
            ],
        ],
        'posts' => ['data' => $postRumahsakits],
    ]);
}


    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return Inertia::render('Rumahsakit/post');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(StoreRumahsakitRequest $request)
{
    $data = $request->validated();

    if ($request->hasFile('image')) {
        $imagePath = $request->file('image')->store('rumahsakit_fotos', 'public');
        $data['image'] = $imagePath;
    } else {
        $data['image'] = null; 
    }

    Rumahsakit::create($data);

    return Redirect::route('rumahsakit.index');
}


    /**
     * Display the specified resource.
     */
    public function show(Rumahsakit $Rumahsakit)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Rumahsakit $Rumahsakit)
    {
        return Inertia::render('Rumahsakit/edit', [
            'post' => [
               'id' => $rumahsakit->id,
                'nama' => $rumahsakit->nama,
                'alamat' => $rumahsakit->alamat,
                'telepon' => $rumahsakit->telepon,
                'nomorwa' => $rumahsakit->nomorwa,
                'maps' => $rumahsakit->maps,
                'transportasi' => $rumahsakit->transportasi,
                'kelas' => $rumahsakit->kelas,
                'ketersediaan' => $rumahsakit->ketersediaan,
                'image' => $rumahsakit->image,

            ]
        ]);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, $id)
{
    $rumahsakit = Rumahsakit::findOrFail($id);

    $validated = $request->validate([
        'nama' => 'nullable|string|max:255',
        'alamat' => 'nullable|string',
        'telepon' => 'nullable|string',
        'nomorwa' => 'nullable|string',
        'maps' => 'nullable|string',
        'transportasi' => 'nullable|string',
        'kelas' => 'nullable|string',
        'ketersediaan' => 'boolean',
        'image' => 'nullable|image|max:2048', 
    ]);

    if ($request->hasFile('image')) {
        $path = $request->file('image')->store('rumahsakit_image', 'public');
        $validated['image'] = $path;
    }

    $rumahsakit->update($validated);

    return redirect()->route('rumahsakit.index')->with('success', 'Data berhasil diperbarui.');
}

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Rumahsakit $rumahsakit)
    {
        $rumahsakit->delete();

        return Redirect::route('rumahsakit.index');
    }
}

this is for my StoreRumahsakitRequest

|string>
     */
    public function rules(): array
    {
        return [
        'nama' => 'required|string|max:255',
        'alamat' => 'required|string',
        'telepon' => 'required|string|max:255',
        'nomorwa' => 'required|string|max:255',
        'maps' => 'required|string',
        'transportasi' => 'required|string',
        'kelas' => 'required|string|max:255',
        'ketersediaan' => 'required|boolean',
        'foto' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
        ];
    }
}

this is for my model

    

this is for my Rumahsakit/post.tsx

import React from "react";
import { Link, useForm } from "@inertiajs/react";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { PageProps } from "@/types";

// Define the types for form data and errors
interface FormData {
    nama: string;
    alamat: string;
    telepon: string;
    nomorwa: string;
    maps: string;
    transportasi: string;
    kelas: string;
    image: File | null; 
    ketersediaan: boolean; 
}

const Create = ({ auth }: PageProps) => {
    const { data, setData, errors, post } = useForm({
        nama: "",
        alamat: "",
        telepon: "",
        nomorwa: "",
        maps: "",
        transportasi: "",
        kelas: "",
        image: null, 
        ketersediaan: false, 
    });

    const [isSubmitting, setIsSubmitting] = React.useState(false);

    // Handle form submission
    function handleSubmit(e: React.FormEvent) {
        e.preventDefault();
        setIsSubmitting(true);
        const formData = new FormData(); 
        formData.append("nama", data.nama);
        formData.append("alamat", data.alamat);
        formData.append("telepon", data.telepon);
        formData.append("nomorwa", data.nomorwa);
        formData.append("maps", data.maps);
        formData.append("transportasi", data.transportasi);
        formData.append("kelas", data.kelas);
        formData.append("ketersediaan", data.ketersediaan ? "1" : "0");
        if (data.image) {
            formData.append("image", data.image); 
        }

        post(route("rumahsakit.store"), {
            data: formData,
            onFinish: () => setIsSubmitting(false),
        });
    }

    return (
        
                    Dashboard
                
            }
        >
            
        
    );
};

export default Create;

and this is for my route

Route::resource('rumahsakit', RumahsakitController::class);

I’ve tried to use parameters in my route and there is no effect on my code

0
  • 0 0 Answers
  • 91 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.