Laravel 5: put, patch and delete requests without using Form builder - laravel

Since in Laravel 5 the form builder class is absent (you can add it, I know), how can I make put, patch and delete requests to match those routes without using any form builder class, just plain Laravel?

You should try adding:
<input name="_method" type="hidden" value="DELETE">
to your form. This is what Form generator do in Laravel 4 - it simply adds hidden input with name _method.
Of course for DELETE value in above example you can put any other methods

Related

How to populate form after validation fails using custom formRequest class in laravel

I am using Custom ForRequest class to validate my form, it works fine. But when it redirects back on form page, the form is not populated.
I don't want to use
old('form_field_name')
My code will be weird if I use old('form_field_name') because I use same form to store and to update the model
What am I missing?
thanks
if you use the same form for store and update, use old with optional. just like
<input name="name" id="name" placeholder="Name" type="text" class="form-control" value="{{ old('name', optional($object)->name) }}">
this is the way you can get the old form values as well as the object values. if there is old value it will put that as value otherwise it will put the object value as value.
make sure to send the object as null from the create function.

WIX: Add custom HTML or my own form (to another website)

I need to create a form that by clicking on it will redirect to another website with special 'inputs' tags values.
something like:
<form action="http://example.com" method="post">
<input type="hidden" name="val1" value="something">
<input type="hidden" name="val2" value="else">
<input type="submit" name="submit" value="Go">
</form>
The custom HTML feature that I find will put it inside an iframe, and it looks bad. Is there a way to do it that will look 'normal'?
If you utilize Wix Code you can develop that inside your Wix page without the need of any html forms.
Simple solution:
- Add the form input elements you need on your page
- Add a button to click on
- Add av event handler to the button and grab the values from the input fields
- Send that data to any site or redirect the user to the site you want using wixLocation.to("url") with the query parameters you might need from the form.

Laravel: How to use destroy with html forms

So since the form helpers arent included in laravel anymore. How do we call for a delete method with regular html forms? I can't find nothing about this, every example uses the form helpers..
thanks
Edit: It works using this:
<input name="_method" type="hidden" value="DELETE">
However, a little bit of explanation would be nice.

How to recognaize which ajax form it is in Django?

I have view which takes care of all the Ajax submits from the client side. And to differentiate them by I uses different submit button names such as this one
<input type="submit" value="Send" name="send_message">
Suggested from this question.
The only problem is that from the view side it doesn't seems to carry the name to the server side so I cannot use the following if-statement
if 'send_message' in request.POST:
It works if I send it normally with page fresh. But I want to use it with Ajax.
I came up with a hack that you can add this name with jQuery. Simply by after serializing() your data you then concatenate the name attribute by data += "&send_message"
Then the if statement will work. But it doesn't seems so clean. So I wonder if there's a better way to handle this? Or should I make different views to handle the different Ajax calls I have?
You really should post each form to a different URL.
If not, you could add a hidden input with the name of the form as the value.
<input name="form_name" type="hidden" value="form_1" />
views.py:
form_name = request.POST['form_name']

Cannot submit form to controller zend framework

I create a from statically in HTML file in view project which is inside the module visit.
I want the controller to handle the request occur when submitting the form
<form action="addVisit" method="post">
<input type="text" name="number"/>
<input type="submit" name="save"/>
The structure of the project is
module visits
controller Visits and it has action addVisit
when submitting the form an error occur, the url becomes like this when submitting the form
http://localhost/zendApps/InspectionSys/public/visits/visits/VisitsController/addVisit
in the controller there is a function action
public function addVisitAction()
{
echo 'here';
}
what should I do ?
First you might reconsider camel caseing your actions addVisitAction() because if you do then you have to deal with view file names like add-visit.phtml I think it will affect urls as well, I find it simpler just to leave action names as lowercase addvisitAction(), this might be part of what's amiss.
Next identify your form actions as /module/controller/action (if you are not using modules you can omit that param), so your action should at least be /visits/visits/addvisit or /visits/visits/add-visit (not quite sure which will work properly) .
also when using html forms that were not generated by Zend_Form you can access the values using $this->getParams() or $this->getParam('paramName') instead of $this->getValues().

Resources