Search code examples
htmlpostmenu

How do i send request to server with post method when using a HTML menu


there is a menu with 5 select key in my HTML program . By clicking each of these keys a request should send to server . I use 'a' tag and href for this . by this approach i have to send request with GET method but i want use POST . For sending request by POST , I use 'form' tag for each of these keys . so for 5 key i use 5 'form' tag . Is this a common and acceptable way? haven't i any better way for sending request with POST? thanks

            <form action="{{url('/defineProject')}}" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}          
                    <input id="a1" class="s1" type="submit" value="define project">                                      
         </form>
        <form action="{{url('/deleteProject')}}" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}          
                    <input id="a2" class="s1" type="submit" value="delete project ">                                         
         </form>
        <form action="{{url('/upgradeProject')}}" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}          
                    <input id="a3" class="s1" type="submit" value="upgrade project ">                                        
         </form>
        <form action="{{url('/reportProject')}}" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}          
                    <input id="a4" class="s1" type="submit" value="report Project">                                      
         </form> 
        <form action="{{url('/editProject')}}" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}          
                    <input id="a5" class="s1" type="submit" value="edit project">                                        
         </form>

Solution

  • <form method="POST" action="YOUR_BACKEND_URL_ENDPOINT">
        <select name="YOUR_FIELD_NAME">
            <option value="VALUE_1"> VALUE_1_NAME </option>
            <option value="VALUE_2"> VALUE_2_NAME </option>
        </select>
        <button type="submit">Submit form</button>
    </form>
    

    I guess this should work.