R
R
Rishat Sultanov2017-04-29 13:10:03
Laravel
Rishat Sultanov, 2017-04-29 13:10:03

How to pull data from multiple POST form?

Good day to all gentlemen :)
I am writing a RESTful API.
I'm trying to get the selected data by the user, so that later I can somehow work with them in the controller.
As a matter of fact, there is: Form
u77144jd.beget.tech - Visual
Code:
https://github.com/Rishats/taskbackend/blob/master...
How to catch the result from this form? By pressing a button?
The documentation does not address this type of form.
If you know places where there are tutors or can help me process this form, please help :)
Thank you all :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mokhirjon Naimov, 2017-04-29
@rishatss

At first:
  • Определите роут для обработки формы
  • Определите класс/метод для обработки запроса
  • В форме укажите урл для обработки запроса:
    <form action="/update" method="POST" accept-charset="UTF-8">
    ...

    В методе который вы определили для обработки запроса, можете сделать так (для получения выбранных значений):
    public function update()
    {
        foreach (request()->multipleselect1 as $value)
            echo "{$value}<br>";
    
        foreach (request()->multipleselect2 as $value)
            echo "{$value}<br>";
    
        foreach (request()->multipleselect3 as $value)
            echo "{$value}<br>";
    
        foreach (request()->multipleselect4 as $value)
            echo "{$value}<br>";
    }

    PS I don't think it can be called an API :).

V
Vitaly, 2017-04-29
@vp7

In code, your form looks like this:

<div class="col-lg-10">
 <select class="form-control" multiple="multiple" id="multipleselect1[]" name="multipleselect1[]">
  <option value="1">Овечка 1</option>
  <option value="2">Овечка 2</option>
 </select>
</div>

The simplest is to access the Select via jQuery, here is an example (not sure due to the use of "[]" in the name) that should work:
alert($("#multipleselect1[] option:selected").val());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question