This is the last problem I am facing with Symfony2. So, I am using a normal form, not the form builder.
I have one table called alert which has the standard fields. I have a second table called booking_class which has an alert key in it which is linked to the alert table. Its a one to many relationship. In my form, I have something like
<input type="text" name="na_booking_class[]">
<input type="text" name="na_booking_class[]">
So this input is placed into an array. Now in my controller, I presume that this will give me my array of data
$alert->setBookingClass($request->get('na_booking_class'));
However, setBookingClass only accepts a String. So I need to somehow loop this array and pass the String values to setBookingClass.
How would this be achieved?
Thanks
If you get an array from this $request->get('na_booking_class'); then you can use:
$arrBooking = $request->get('na_booking_class');
foreach($arrBooking as $booking) {
$alert->setBookingClass($booking);
}
Try with this.
Related
How can i create a form like the one on linkedin. On form input type when i type is going to fect data from a database if not existis is going to create it and fetch d and store to another table
on form input type, immediately get result: This can be done by AJAX. Laravel support Vue which can do this easily:
1a. call a function in the mounted() part.
1b. the function call itself by putting setTimeout(this.functionName,1000) at the end.
1c. in the function, check if the text in the text box is changed. if yes, make a request by axios.get('blablabla').then(response=>{//put the response into vue dataArrayName in data part});
1d. the html template is auto-updated by v-for="dataArrayName"
looks like the search is done by comparing char by char from the beginning of the string to the data.
if you press enter, pass the search string to the controller, use some logic to determine whether it is needed to create row in database
Hi! I want custom field data, because I have many arrays in one array.
I try using field: 'LeftNavigation.Title' but it didn't work.
You can't using multi Array data in field
Maybe you should choose another solution for this
Suggest : Create Leftnavigation Field , when click on this field it's show a second table show data from Leftnavigation array
I am using Select2 Tags using a dropdown as well as a direct input and have the following code in my View:
<select id="lessonTags" class="form-control" multiple="multiple" style="width:100%" name="SelectedTags">
#foreach (var lesson in Model.Lessons)
{
<option value="#lesson.Id">#lesson.Title</option>
}
In my viewmodel I just created a temp variable string[] SelectedTags which gives me the string of what was selected via the dropdown as well as anything that was typed in that was not in my original options.
So currently I have to loop through my data and match to see if the SelectedTags array has a match on my db, if it does then I can use that Id in my model, if it doesn't exist then I have to Create that lesson in my DB.
I find this to be extra processing, it would be nice if I can just pass say a key, value pair of ID/Lesson.Title and anything that I typed wouldn't have an ID so I can easily identify what needs to be created on the DB.
Is there a way to pass the key/value pair via the name tag?
EDIT: Currently whats getting returned is the lesson.Id if its in the list or the actual text if its not - the issue with this is if the user types in a number, i can't discern between an Id and the users number...hence I am thinking I need to somehow flag a new piece of data.
I have a form input field in Thymeleaf. The field (bookingEntry.datefrom in the code snippet below) is type Date. I use a datepicker to allow the user to select and format the required date to enter the field. This is all fine.
However, I want the initial value of the date (which I have set to the current date) to be displayed in the format that I choose. So, how do I format the date initially shown in a th:field. th:value is ignored (Thymeleaf is getting the value from the backing object, as it should) and I can't seem to apply a format to the th:field.
Thymeleaf code is:
<input type="text" class="form-control getdate"
th:field="*{datefrom}" placeholder="Date From"
th:value="${#dates.format(bookingEntry.datefrom, 'dd-MMM-yyyy')}"/>
I'm sure that I could use a String which is initialise in any format that I choose, rather than a Date type, but I wondered if there was a way to format initial values in a th:field?
Many thanks
I missed the simple answer, simply because of my limited knowledge of Spring. I'm adding it here incase it helps any other novices like me.
The #DateTimeFormat annotation on the element in the object being passed to the form does the job. It ensures that the Date object is formatted in the way that you wish (irrespective of whether you are using Thymeleaf or not).
In the example above, within the bookingEntry object
#Temporal(DATE)
#DateTimeFormat (pattern="dd-MMM-YYYY")
private Date datefrom;
In case your date is null, it will give you error. We have to check the value before we parse the date.
<input type="text" name="date"
th:value="${user.dateOfBirth}?${#dates.format(user.dateOfBirth, 'dd-MM-yyyy')}:''"
placeholder="dd-mm-yyyy" id="pickyDate"/>
I'm trying to write a Form Builder system.
Now, i reached to gathering information section and at this section i need to grouping the information to three group like:
"Short-Response" for text inputs
"Long-Response" for textarea
and "Option-Response" for radio, checkbox and dropdown
in Form page view, system create the form, based on database records.
I'm using suffix for inputs based on those group as i said earlier, like these:
<inputs name="dynamicpart_short" value="" />
<textarea name="dynamicpart_logn"></textarea>
Now, In server side i want to gather these information and group them.
I'm using
for each item in Request.Form
Next
But how i can create a loop based on inputs suffix like "_short" or "_long" and ....
means each suffix has it's own loop!
PS:
inputs have a name with two parts, first part is dynamic and is a random numbers!
Like this: name="15_short"
"item" will have the name of the form field, use a string function to check if it has short or long in it:
for each item in Request.Form
if instr(item,"_short")<>0 then
'do something
elseif instr(item,"_long")<>0 then
'do something else
'.....
end if
Next