The information entered into dynamically generated text fields is not being successfully passed to the request()->validate() array

My form allows users to input their educational background from Elementary school to College. If they wish to include any additional studies, they can click the "Add Other Studies" button, which will then reveal a new set of input fields specifically for other educational experiences.

 {{-- Button --}}
<tr>
        <td scope="col"><button type="button" onclick="addOtherStudies()" name="add-educ-exp" id="ar-educexp" class="btn btn-outline-primary">Add Other Studies</button></td>
</tr>
 {{-- Add Other Studies section --}}
 {{-- .d-none is display:none --}}
 <tr  class="d-none" id="otherStudiesRow">
          <th scope="row"><label for="other">Other Studies</label>
                    <input type="text" name="otherStudies[0]other_studies_name"/>
                    Degree/Major:<input type="text" name="otherStudies[0]other_studies_degree_major" placeholder="Masters Degree, Doctorate, Associate$quos, etc." />
          </th>
            <td>
                   <input type="text" style="width: auto; margin-top: 2rem;" name="otherStudies[0]other_studies_year"/><label for="units">If not complete, enter no. of units taken:</label><input type="text" style="width: auto;" name="otherStudies[0]other_studies_units" cols="10"/>
          </td>
           <td><textarea name="otherStudies[0]other_studies_awards" rows="3" cols="30"></textarea></td</tr>
                                <tr class="d-none" id="otherStudiesbuttons">
                                    <td><button type="button" onclick="addEducation()" name="add-educ-exp" id="ar-educexp" class="btn btn-outline-primary">Add Education</button></td>
                                    <td><button type="button" class="btn btn-outline-danger remove-input-field">Delete</button></td>

                                </tr>

I utilized the JavaScript classList property to toggle the visibility of the input fields dynamically as needed in this scenario. dynamicAddRemove.js :

function addOtherStudies(){
    var section = document.getElementById("otherStudiesRow");
    var buttons = document.getElementById("otherStudiesbuttons");

        section.classList.remove("d-none");
        buttons.classList.remove("d-none");

}

However, upon entering data into the added otherStudies input fields and attempting to save it, I noticed that the values are not being transmitted to the request()->validate() array: This is an excerpt from my controller:

        $validatedEducExp = request()->validate([
            //education start at 0, length 12
            "elementary_name" => ['nullable','required_with:elementary_year,elementary_awards','max:100',new LetterSpaceOnly],
            //more validation rules here...
        ]);

When inspecting the submitted data using ddd(), only partial information shows up with the absence of the 'otherStudies' array, hindering its inclusion in the validation process:

array:19 [▼
  "elementary_name" => null
  // more fields...
]

Interestingly, when revisiting the page, the inserted data remains in the 'otherStudies' field due to the use of the old() helper function, indicating that the details are stored temporarily in the session but are unable to proceed to the validate() function. What could be causing this issue?

Answer №1

Update the input names to the following:

otherStudies[0][nameOfOtherStudy]
otherStudies[0][degreeMajorOfOtherStudy]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to minimize the size of Nextjs Static HTML Export page on disk

While utilizing Nextjs Static HTML Export, I've noticed that each page (consisting solely of HTML code) is being generated with a file size of over 100kb on disk. Are there any methods available to decrease the page size on disk? ...

How do I enable automatic playback for a vimeo video using the embed tag?

Currently, I am facing a challenge with the following embed tag in my HTML file: <embed src='{{"https://player.vimeo.com/video/{$videouri}?autoplay=true"}}'width="300" height="361" /> I am experiencing difficulties when trying to use the ...

Embed Text inside an HTML Canvas

As someone who is relatively new to working with html canvas, I am having a bit of trouble when it comes to containing text within the canvas area. Specifically, I am pulling text from a textarea and displaying it on the canvas, but it seems to stay as one ...

Issue with Vue template not displaying within a loop

After completing a basic Vue tutorial on setting up a Todo app, I decided to integrate some aspects of it into a website I am developing. However, I have encountered an issue with my for-loop that is not functioning as expected. The project was initially ...

Is there an issue preventing Three.js from rendering properly?

I created a simple file to experiment with the Three.js library, however I encountered an issue when trying to add the renderer (an element) to the $container (which is defined as $('#container')). <!DOCTYPE html> <html lang='en&ap ...

Display a video modal upon page load, allowing users the option to click a button to reopen the modal

Looking for a way to make a video modal automatically open on page load and allow users to reopen it by clicking a button? Here's a snippet of code that might help you achieve that: HTML <html> <head> <link rel="stylesheet ...

How can one effectively access a nested JSON value in Angular by concatenating all fields?

If we have a JSON stored in the variable person like below: { "firstName": "First Name", "lastName": "Last Name", "address": { "city": "New-York", "street": "Some Street" } } To access the value of street, we would typical ...

Enabling hover effects to scroll divs only when interacted with

I am aiming to achieve two separate scrolling divs and I'm uncertain about the exact approach. Experimenting with various overflow properties has only resulted in one scrolling independently. .profile { width: 100%; display: flex; ...

Encountering a segmentation fault error, yet at a loss for how to resolve it

I am struggling with a code that is causing a segmentation fault, and debugging it has been challenging for me. It seems like my lack of knowledge in C syntax might be the reason behind this issue, even though I have already gone through TCPL. #include ...

Using jQuery's click function to manipulate multiple div elements

Currently, I am attempting to use jQuery's click function in order to implement a hover effect on a selected div without having to differentiate between the divs in the JavaScript code. Here is what I have so far: $(document).ready(function(){ $ ...

What distinctions can be made between Controlled and Uncontrolled Components when using react-hooks-form?

Trying out the React Hooks form, I came across some interesting concepts like controlled and uncontrolled forms. Controlled Form <form onSubmit={handleSubmit(onSubmit)}> <input name="firstName" ref={register({ required: true })} /> ...

Implementing Google Maps on a webpage with a dynamic drop-down form using a combination of Javascript and PHP

On my HTML page, I have two drop-down lists populated with data from a MySQL database including latitude, longitude, and address. The user selects an item from the first drop-down and clicks submit. Upon submission, I want to display a Google map with a m ...

steps for eliminating specific words from an input field

In my form, I have 13 input boxes where users can only type text and numbers. I am using the following script to enforce this rule: RESTRICT INPUT TEXT $(function() {//<-- wrapped here $('.restrict').on('input', fun ...

How to retrieve the class of a dynamic div by clicking on a different div using jQuery?

I am trying to retrieve the class of a dynamic div when clicking on another div with the class name "div.secondclass". Below is my code snippet: $(document).ready(function() { $("div.secondclass").click(function () { firstclass=$('#firsti ...

Unexpected outcomes arise when parsing headers from a file-based stream

Currently, I am in the process of creating a small parser to analyze some log files using node streams (more specifically io.js). I have been referring to the documentation for unshift to extract the header. While I can successfully divide the buffer and ...

Exploring the Power of Promise Chaining: Understanding the Distinction between .animate and setTimeout

I am seeking clarification on how promises work in JavaScript. I am struggling to understand the difference between executing a chain composed of jQuery.animate and setTimeout. For example, if I write the code below: var promise = new Promise(function(re ...

Is it Possible to Remove an Item from an Array in Vue without Explicitly Knowing the Array's

I'm currently working on a feature that involves removing an item from an array when it is clicked. The code I have so far looks like this: <span @click="deleteItem(index)" v-for="(item, index) in customTaxonomies.featured" v-html="item"></s ...

Extract a property from a JSON object

Is there a way to access the href properties and use them to create multiple img elements with their sources set as the extracted href properties? I'm looking for a solution in either javascript or jQuery. I attempted the following code, but it didn& ...

Change an array of objects into a map where each object is indexed by a unique key

I'm attempting to transform an array of objects into a map, with the index based on a specific attribute value of the object in typescript 4.1.5 Additionally, I am only interested in attributes of a certain type (in this case, string) A similar ques ...

Revamp the sequence of divs using jQuery

<div class="example first">111</div> <div class="example second">222</div> <div class="example third">333</div> Can the order of these divs be changed using jQuery? I am looking to get: <div class="example second"&g ...