I have a vuejs component that contains a form, I want to use the laravel old function so I'm able to repopulate the input fields if the form validation fails.
My guess would be I'd need to do something like pass the old function in as a prop to the component possibly but not sure if this is the 'right' way of doing it.
I'm just looking for confirmation on the best way of doing this.
If you are not using ajax requests then yes the only way is to pass them as props. Probably send the whole array as one prop: <component :oldInputs="{{old()}}"></component>
Related
I'm using Laravel with a Vue component called vue-good-table. I just want to pass an array from my component to one of my Laravel routes and consequently to the respective controller.
I tried with axios but in this case it doesn't work, because the controller that receives the data must return straight away a Laravel view (but using axios the view is returned to the Vue component method as a response).
Maybe I can try to use a button that calls the route but I'm having trouble passing the array I need to pass. The route I specified must use the GET method.
MyTable.vue
<a :href="/pdf-download-selected/">
<button>Download PDF</button>
</a>
I really don't understand if my approach to Laravel with Vue is completely wrong or what..I mean I know how to pass data from Laravel to Vue, but not the opposite.
What do you recommend I do?
Thanks!
I have a Controller that parses an XML and returns a view with a list of names and URLs.
return view('view_1',compact('myList'));
View_1 will have a form with parameters method="POST" action="goToView_2"
Then I get some information from my view_2 through a POST, but I still want to keep $myList so that view_2 view uses it aswell.
How do I pass $myList from the first view to the next through a controller?
It sounds like you're trying to have multi-step form of some kind.
I would store the data in the session and easily access it in the second controller or in the view (although not recommended).
https://laravel.com/docs/5.4/session#using-the-session
PS. I personally love using the global session helper.
Is it possible to fill Backbone model with data from laravel cache, and how can I do it ?
Even if i don't know laravel i think this is quite possible. You only need to "render" or "print out" your laravel cache into a JavaScript code block. Please also see Passing PHP variable into JavaScript to see how you can pass values from php to JavaScript.
A good solution would be, if you can render out your laravel cache to json form and then pass this to the "model.set()" method of your Backbone model.
I would like to validate both single field and multiple field data from a CakePHP form.
The single field validation should be done on blur from each field while the multiple field validation should be done on submitting the form.
I would like to use the $validate property declared in the Model for validating data and I would like to display the errors near each field (single field validation) and on top of the form (for multiple field validation).
My main goal is to achieve this the most "caky" way (if there is one for validating data with jQuery). I couldn't find any useful advice out there and I'm asking you for some help to get this going.
One of my concerns is how shall I pass data from the form to jQuery and then to the action that does the validation and also how shall I return and display the errors, if there are any.
Thank you in advance!
I'd suggest first making sure everything works without jQuery, then use the jQuery Form plugin to submit your forms via AJAX. If you include the RequestHandler component in your AppController, you should find that your controllers distinguish automatically between AJAX and synchronous requests.
OK, so I coded my own solution to this, but I am still waiting for a more "caky" approach.
I made two generic jQuery functions, one for single field validation and one for multiple field validation. The function should grab the data from the specified form and send it to the form's action via AJAX, to a specially created controller method which will attempt to validate data and output an AJAX response ("" for validation has passed and errors for errors in validation). Then, the result is checked in the jQuery function and the default form behaviour is triggered only if the validation has passed. Otherwise, display the errors and return false; to prevent default submission.
I know that CodeIgniter already elegantly handles URL's. What I have is a form with multiple elements (date, keyword, location = optional). Is it possible to set up CI to create a URL that looks like:
mysite.com/class/function/date/keyword?
If you are using CodeIgniter's form helper, it sends your form data via POST, so you can't easily have your field's value displayed in the url.
What you could have, though, is a controller method that collects your form data and redirects to the url you want.
If you need further clarification, please let me know.
Yes, you can use the anchor function by passing the relevant info to it.