Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel form post data from placeholder value

I want to pass the data on a form placeholder without user input, want to know if that is possible…

Below is my form in view

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
        <form action="kind" method="POST">
         @csrf
         <div class="form-group">
    <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-user" style="font-size:24px"></i> Name</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="name" placeholder="{{ auth()->user()->name }}" >
    <small>Type your name as given on the placeholder</small>
  </div>
  <div class="form-group">
    <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-building-o" style="font-size:24px"></i> Organazation</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="organazation">
    <small>Type your organazation</small>
  </div>
  <div class="form-group">
    <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-map-marker" style="font-size:24px"></i> Country</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="country">
    <small>Enter country</small>
  </div>
  <div class="form-group">
    <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-map-marker" style="font-size:24px"></i> Project name</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="title">
    <small>Enter the name for the project</small>
  </div>
  <div class="form-group">
    <label for="exampleFormControlTextarea1"><i style="color:#000" class="fa fa-comment" style="font-size:24px"></i> Describe project</label>
    <textarea type="text" class="form-control" id="exampleFormControlTextarea1" rows="3" name="message"></textarea>
    <small>Describe the project in details</small>
  </div>
  <div class="form-group">
    <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-phone" style="font-size:24px"></i> Contacts</label>
    <input type="text" class="form-control" id="exampleFormControlInput1" name="contact">
    <small>Enter office contacts here</small>
  </div>
  <form action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
            @csrf
            <div class="row">
  
                <div class="col-md-6">
                    <input type="file" class="form-control" name="imogi">
                </div>
            </div>
            <small>Select business logo if any or implicating image</small>
            <br/>
            <br/>
            <button type="submit" class="btn btn-primary">Send</button>
        </form>
        <br/>
</form>
        </div>
    </div>
</div>
@endsection

…below is my controller

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php

namespace App\Http\Controllers;

use App\Kind;
use Illuminate\Http\Request;

class KindController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function display(Request $request)
    {
        $request->validate([
            'name'=>'required',
            'organazation'=>'required',
            'country'=>'required',
            'title'=>'required',
            'message'=>'required',
            'contact'=>'required',
            'imogi'=>'required'
           
        ]);
        $Kind = new Kind;
        
        $Kind->name = $request->input('name');
        $Kind->organazation = $request->input('organazation');
        $Kind->country = $request->input('country');
        $Kind->title = $request->input('title');
        $Kind->message = $request->input('message');
        $Kind->contact = $request->input('contact');
        $Kind->imogi = $request->input('imogi');
        $Kind->save();

        return redirect()->back();

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Kind  $kind
     * @return \Illuminate\Http\Response
     */
    public function show(Kind $kind)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Kind  $kind
     * @return \Illuminate\Http\Response
     */
    public function edit(Kind $kind)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Kind  $kind
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Kind $kind)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Kind  $kind
     * @return \Illuminate\Http\Response
     */
    public function destroy(Kind $kind)
    {
        //
    }

And this is my route

Route::POST(‘/kind’, ‘KindController@display’)->name(‘kind’);

Data is being submitted in the database from user input, but that`s not what i want…i want to capture authenticated user name without user manually inserting it

>Solution :

You need to pass the username through the value attribute, but make the input element read-only like this:

<input type="text" class="form-control" id="exampleFormControlInput1" name="name" value="{{ auth()->user()->name }}" readonly>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading