save data from two forms to the database in laravel - laravel

How do save data into a database with a button that is located different from the input form?
this is my sample code
<form action="{{ route('store') }}">
#csrf
<input type="text" name="title"></form>
<form action="{{ route('store') }}">
#csrf
<button class="btn" type="submit">Submit</button></form>
when I run the code above, and output it via dd (...). it can't run. can the above code be used or do I have to combine the two things? when I wrap all of my divs with forms, it looks unresponsive (sorry, if my english so bad)

Related

Laravel not rendering form element, but only the contents inside

I have been stumped on this for a couple hours and can not figure a way around it.
Larvel 8 with Livewire
I have a very basic form.
<form action="/dashboard/payment" method="POST">
#csrf
<button type="submit" class="btn btn-primary my-3 w-100" id="checkout-button">
<span wire:loading>Please Wait</span>
<span wire:loading.remove>Pay - $
<span>100</span>
<br>
<small>Description of payment</small>
</span>
</button>
</form>
But the form tag itself it is not rendering the html. It is only rendering the button inside.
When incrementing a value with another button, the form tag is then rendered into html and the button can be used as expected.
The incrementing button only ++ to a value and updates the database with the new value.
This is the only thing holding me back, I have searched everywhere but cant find any information about form tags not rendering.
Note: Neither the opening tag or the closing tag is rendered until the other button is pressed.
Any ideas or information would be fantastic and greatly appreciated.

Multiple file input type overriding selected files and upload only last file selected

I am trying to build a form that upload multiple images. below is my code
<form method="post" action="{{ route('addproduct') }}" enctype="multipart/form-data">
<div class="custom-file">
<input type="file" class="custom-file-input" id="image" name="image[]" multiple>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
<div class="row mt-4">
<div class="row" id="preview_img">
</div>
<button type="submit>Submit</button>
</form>
and on the server side I do
dd($request->image);
The problem is, if I click the input field and select more than one file using shift/ctrl click and upload, it works fine uploading all the selected files but if say I click on the browse and select one file and then again click on browse and select one more file and repeat, it just keep the last file selected.
If that is how it is suppose to work then is there a way to make it work the way I want where user can select multiple files using browse button multiple times because the files user want to upload might not be in the same folder so he/she might want to browse multiple times to select all files they want to upload.

MethodNotAllowedHttpException in submitting equation format from form textarea (ckeditor)

Hi there I am submitting a equation from ckeditor and geting MethodNotAllowedException though my form has method type post and route also post.
Here is my view.
<form class="form-horizontal" action="{{route('set-question')}}" id="submit_form" method="post">
{{csrf_field()}}
<div class="col-md126 col-md-9 col-md-offset-1">
<label class="control-label">Question</label>
<p class="help-block" style="font-size:12px;">Question is required</p>
<textarea name="question" class="ckeditor"></textarea>
<input type="submit" class="btn btn-success" value="Submit">
</div>
</form>
If I type this or some other equation only then other problem arise. I have saved by typing other format even with bengali language that was good. Bellow is my route and then the typography I was able to save in db via this route and view.
Route::post('add-question','Admins\ExamController#addQuestion')->name('set-question');
The successful tries.
But after the highlighted equation or format i got MethodNotAllowedHttpException.
Please suggest me what I'm missing.
Thank you in advance.
You can clean your cache. Because i faced sometime this type of problem and after clean my cache it will be fine.
One thing you can try with name route like: name('set.question)

Hidden inputs are missing from Request in Asp.net mvc3

I'm using asp.net mvc3 ajax.beginform, and recently I've encountered a very strange problem.
It seems that some of the hidden input's I've placed inside the form do not exist in the request object.
I am not changing these values in any way after the post.
Any idea what is the reason?
Here's an example of a form that's giving me some trouble.
<form action="/PriceListItems/PriceUpdate" data-ajax="true" data-ajax-method="Post" id="form0" method="post">
<input id="item_Id" name="item.Id" type="hidden" value="3">
<input id="price_TariffId" name="price.TariffId" type="hidden" value="1">
<input class="input-mini"
data-val="true"
data-val-number="The field Price must be a number."
data-val-regex="incorrect number"
data-val-regex-pattern="(^N/A$)|(^[-]?(\d+)(\.\d{0,3})?$)|(^[-]?(\d{1,3},(\d{3},)*\d{3}(\.\d{1,3})?|\d{1,3}(\.\d{1,3})?)$)"
data-val-required="שדה זה הינו חובה"
id="itemTariff_3_1"
name="price.Price"
onchange="postThis(this);"
type="text"
value="300.00">
<span class="help-block">
<span class="field-validation-valid"
data-valmsg-for="itemTariff_3_1"
data-valmsg-replace="true"></span>
</span>
</form>
Thanks!
solved it, but it was quite a disappointing solution..:
i've replaced every jquery related script in my site so that it'll arrive from a CDN rather from my local files, but in the original versions.
and that was it.
everything suddenly started to click together.
frustrating, but works.
thanks,
Nir

Can you mix and match Spring form tags and regular HTML form tags in a single HTML form?

I have a legacy HTML form that I want to make into a Spring form. Do I need to switch all of the form tags to Spring form tags or could I mix and match them as I please?
In other words, something like this:
<form:form modelAttribute="mymodel" action="/somecontroller/someaction" method="post">
<input type="text" name="something" value="">
</form:form>
instead of this (using only Spring form tags):
<form:form modelAttribute="mymodel" action="/somecontroller/someaction" method="post">
<form:input path="something" />
</form:form>
You can use regular <input /> elements within a <form:form /> without any problems. This is the conventional way to add submit buttons to a Spring form.
See here for more information.

Resources