Get value other than input polymer+laravel - laravel

I am trying to use laravel with polymer. I have built a form that looks like this
<form action="{{ url('settings/update') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<h4>Choose your theme</h4>
<paper-radio-group selected="1">
<paper-radio-button name="1" label="Theme Default"></paper-radio-button><br/>
<paper-radio-button name="2" label="Theme Violet"></paper-radio-button><br/>
<paper-radio-button name="3" label="Theme Orange"></paper-radio-button><br/>
</paper-radio-group><br/>
<button type="submit" class="mui-btn mui-btn-primary">Change Theme</button>
</form>
But I have no idea how to retrieve those fields in my controller. Any help would be appreciated.

Form elements don't know how to work with custom elements like paper-radio-button. You could replace your form with ajax-form or use some JavaScript to handle the form submit event, gather up the values, and send the request yourself.

Related

put query params inside a filter key laravel

hi i want to change this url from get form
http://127.0.0.1:8000/allfiles?category_id=1&file_id=1
to this in laravel
http://127.0.0.1:8000/allfiles?filter[category_id]=1&filter[file_id]=1
how can i do that?
Actually i want change perquery=? to filter[perquery]=?
thanks
Try something like this in the blade (you can modify it if need):
<form action="http://127.0.0.1:8000/allfiles" method="GET">
<input name="filter['category_id']">
<input name="filter['file_id']">
<input type="submit">
</form>

Append data to form using through DOM?

Form which uses POST method:
<div>
<form action="{{ route('post.store') }}" method="POST">
<input type="text" name="name">
<input type="text" name="text">
<button type="submit">Submit</button>
</form>
#foreach ($comments as $comment)
{{ $comment->text }}
Reply
#endforeach
</div>
Array of $comments is being returned when the view itself is returned.
Basically, I am intrested if there is a way to append $comment->id to the data that will be sent to server on Submit button click using Laravel Blade or AlpineJS, but without creating any additional functions between <script> tags? I mean, is it possible to do something like this: Reply?
EDIT:
I expressed myself wrongly. I don't want to append new id every time Reply is clicked, but to overwrite corresponding property in data which is going to be sent to server when Submit button is clicked with the $comment->id for which Reply was clicked for.
I assume you are using Laravel Resource Controller
Not sure I totally understand why you want to send all comment ids when submitting the form but when calling the route post.store you should better send the post id
<form action="{{ route('post.store', ['post' => $post]) }}" method="POST">
If you want to get all comment id and have proper model relationships set up in your models you can get all comments for a post in your controller.
To send a specific id in your form create a new <input name="comment_id" value=""> and let that field be populated.

Thymeleaf form array with default values

I'm using Spring+Thymeleaf to see and modify the users in a database. I would like to set the input fields to the actual values of an original user but I've tried with different styles and it doesn't work.
With the present configuration I can update information of users and see the id of original user (it's not in a input field) but I can't show the actual configuration in input field as default.
CONTROLLER:
#GetMapping(value = {"/", ""})
public String subusersPage(HttpSession session, Model model) {
String idUser = BaseController.getLoggedUser(session);
UserDTO userDTO = userService.getUserById(idUser);
model.addAttribute("subusersDTO", userService.getSubusersDTO(userDTO.getSubusers()));
model.addAttribute("populations", userDTO.getPopulations());
model.addAttribute("configurations", userDTO.getConfigurations());
model.addAttribute("attributes", userDTO.getAttributes());
model.addAttribute("subuserDTO", new SubuserDTO());
return "subusers";
}
HTML:
<th:block th:each="subuserDTO_original : ${subusersDTO}">
<hr>
<form action="#" th:action="#{/subusers/__${subuserDTO_original.id}__}" th:object="${subuserDTO}" method="post">
<div>
<p th:text="${'Id: ' + subuserDTO_original.id}"></p>
<p>Name: <input type="text" th:field="*{name}" th:name="name" th:value="${subuserDTO_original.name}"/></p>
<p>Population: <input type="text" th:field="*{population}" th:name="population" th:value="${subuserDTO_original.population}"/></p>
<p>Configuration: <input type="text" th:field="*{configuration}" th:name="configuration" th:value="${subuserDTO_original.configuration}"/></p>
<p>Attributes: <input type="text" th:field="*{attributes}" th:name="attributes" th:value="${subuserDTO_original.attributes}"/></p>
<p>
<button type="submit" th:name="action" th:value="update">Update</button>
<button type="submit" th:name="action" th:value="delete">Delete</button>
<button type="reset" th:name="action" th:value="clear">Clear</button>
</p>
</div>
</form>
<form action="#" th:action="#{/subusers/__${subuserDTO_original.id}__}" method="get">
<button type="submit">Default</button>
</form>
</th:block>
Any help will be very appreciated, thank you!
If you want to edit an existing user, then your th:object (which is ${subuserDTO} in this case) needs to be populated with the values of the original user. This is because when you use the attribute th:field="*{name}", it actually overwrites the name, id, and value of the html tag (which is why th:value="${subuserDTO_original.name}" isn't working.
Two other options you could do:
You could also set name="name" and use th:value instead.
Or another option, you could use ${subuserDTO_original} as your th:object.

Laravel Get Method Not Supported Exception (While the form method is already POST)

I am working on a Laravel project in which I have a form to write styled text, inside the form I used WYSIWYG editor, and the method of the form is POST. Sometimes when I submit the form it gives me (The GET method is not supported for this route. Supported methods: POST). This usually occurs when I give some styling to my text e.g. adding background color or inserting Arabic Characters. but when I insert plain text English words It works as expected and every things ok.
I added the header("Content-Type: text/html;charset=UTF-8"); at the top of index.php file but the result was not changed
Note: the application works in my local xampp server, but when I upload online I get the problem.
Here is form.blade.php (view)
<form method="POST" action="{{action('MainController#Insert')}}" accept-charset="utf-8">
{{csrf_field()}}
#method('post')
<input type="text" name="title" class="form-control" placeholder="Title"/>
<textarea name="details" id="myeditor"></textarea>
<input type="submit" value="Save"/>
</form>
<script>
CKEDITOR.replace('myeditor');
</script>
Here is my web.php (Routes)
Route::get('/', function () { return view('welcome'); });
Route::get('/form','MainController#LoadForm');
Route::post('/save','MainController#Insert');
And the is my controller
public function LoadForm(Request $req){
return view('form');
}
public function Insert(Request $req){
DB::table('notes')->insert(["title"=>$req->title,"details"=>$req->details]);
return redirect()->back()->with(["message"=>"Note Saved Successfully!"]);
}
Where is the problem?
to simplify it
<form method="POST" action="/save" accept-charset="utf-8">
{{csrf_field()}}
<input type="text" name="title" class="form-control" placeholder="Title"/>
<textarea name="details" id="myeditor"></textarea>
<input type="submit" value="Save"/>
</form>

Codeigniter auto change the input field value

when i give an input field value as blackhat%%1985 and submit i get the post value as blackhat%85
the value is changed after require_once BASEPATH.'core/CodeIgniter.php';
<form action="" method="post" id="submitForm">
<input type="hidden" name="a" value="blackhat%%1985" />
<input type="submit" name="b" />
</form>
use urlencode() function for this.
You can use JavaScript's encodeURIComponent to encode the value before submitting the form.
encodeURIComponent('blackhat%%1985');
Of course, don't forget to decode it on the server-side after that.

Resources