Livewire Is not able to store - laravel

I have four laravel live wire components. The first component is Step1 which has the values `
`class Step1 extends Component
{
public $firstName;
public $lastName;
public $middleName;
public $prefix;
public $suffix;
public $dateofbirth;
public $gender;
public $phonenumber;
public $emailaddress;
public $step;
public function mount()
{
$this->step = 1;
}
public function nextStep()
{
$this->step++;
}
public function prevStep()
{
$this->step--;
}
public function render()
{
return view('livewire.step1');
}
}
`
Step 2
'<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Step2 extends Component
{
public $step;
public $contact_last_name;
public $contact_first_name;
public $contact_address_one;
public $contact_address_two;
public $contact_country;
public $contact_province;
public $contact_city;
public $contact_email;
public $emergency_phone_coder;
public $citizen_bio_id;
public function mount()
{
$this->step = 2;
}
public function nextStep()
{
$this->step++;
}
public function prevStep()
{
$this->step--;
}
public function render()
{
return view('livewire.step2');
}
`
and step 3
<?php
namespace App\\Http\\Livewire;
use Livewire\\Component;
class Step3 extends Component
{
public $step;
public $country;
public $state;
public $message;
public $date_of_travel;
public $date_of_return;
public $purpose_of_travel;
public $citizen_bio_id;
public function mount()
{
$this->step = 2;
}
public function nextStep()
{
$this->step++;
}
public function prevStep()
{
$this->step--;
}
public function render()
{
return view('livewire.step3');
}
}`
All these steps are managed in the FormWizard Component
`<?php
namespace App\\Http\\Livewire;
use App\\Models\\CitizenBio;
use Illuminate\\Support\\Facades\\DB;
use Livewire\\Component;
class FormWizard extends Component
{
public $step;
public $firstName;
public $lastName;
public $middleName;
public $prefix;
public $suffix;
public $dateofbirth;
public $gender;
public $phonenumber;
public $emailaddress;
public $contact_last_name;
public $contact_first_name;
public $contact_address_one;
public $contact_address_two;
public $contact_country;
public $contact_province;
public $contact_city;
public $contact_email;
public $emergency_phone_coder;
public $country;
public $state;
public $message;
public $date_of_travel;
public $date_of_return;
public $purpose_of_travel;
public function mount()
{
$this->step = 1;
}
public function nextStep()
{
$this->step++;
}
public function prevStep()
{
$this->step--;
}
public function render()
{
return view('livewire.form-wizard', ['step' => $this->step]);
}
public function store()
{
$data = [
'first_name' => session('firstName'),
'last_name' => session('lastName'),
'middle_name' => session('middleName'),
'prefix' => session('prefix'),
'suffix' => session('suffix'),
'date_of_birth' => session('dateOfBirth'),
'gender' => session('gender'),
'phone_number' => session('phonenumber'),
'email_address' => session('emailaddress'),
// ...
];
DB::table('citizen_bios')->insert($data);
$this->reset();
return redirect()->route('/dashboard');
}
public function debug()
{
return $this->step;
}
}`
When a user clicks the submit form that is linked to the FormWizard Component to run the store function It does not store the data into the DB.
I checked to make sure I've linked the component to the correct input which I believe I did as so
`<form>
<div class="grid gap-6 mb-6 md:grid-cols-3">
<div>
<label for="first_name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">First name</label>
<input wire:model="firstName" wire:error.class="invalid" type="text" name="first_name" id="first_name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-black dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Kwesi" required>
</div>
`
and in the FormWizard.blade this is how it looks
<div wire:loading.remove>
<form method="POST" action="{{ route('store')}}" id="postCitizen" accept-charset="UTF-8" style="display:inline-block">
#csrf
#method("POST")
#if ($step === 1)
#livewire('step1')
<div class="grid gap-6 mb-6 md:grid-cols-1">
<button wire:click="nextStep" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-white-600 dark:hover:bg-white-700 dark:focus:ring-white-800">Next</button>
</div>
#elseif ($step === 2)
#livewire('step2')
<div class="grid gap-6 mb-6 md:grid-cols-2">
<button wire:click="prevStep" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-white-600 dark:hover:bg-white-700 dark:focus:ring-white-800">Previous</button>
<button wire:click="nextStep" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-white-600 dark:hover:bg-white-700 dark:focus:ring-white-800">Next</button>
</div>
#elseif ($step === 3)
#livewire('step3')
<div class="grid gap-6 mb-6 md:grid-cols-2">
<button wire:click="prevStep" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-white-600 dark:hover:bg-white-700 dark:focus:ring-white-800">Previous</button>
<button wire:click="store" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Submit</button>
</div>
#endif
</form>
<div>
{{$this->debug()}}
</div>
</div>`
I tried change how the store function runs, and I've made sure the blade fire uses wire:model="firstName". What i don't know where the issues is coming from that when I click the submit button all my values say null even though I've typed in it.

Related

AlpineJS x-for not running after x-data update

I am running into a very strange issue where I have a chatroom that should update whenever a new message is posted. Instead when I add a new message the x-data is getting updated and I can see the message there but the x-for doesnt seem to run and it never appears on the frontend. Then when I enter another message the previous message shows up on the frontend but the latest message does not show even though the x-data has been updated to reflect it.
Here is the code below:
<div
x-data="{{ json_encode(['messages' => $messages, 'messageBody' => '']) }}"
x-init="
Echo.join('chat.2')
.listen('ChatSent', (e) => {
#this.call('incomingMessage', e)
console.log(e)
})
">
<div
class="wow fadeInUp mb-10 rounded-md bg-light-bg dark:bg-dark"
data-wow-delay="0s"
>
<h3
class="border-b border-body-color border-opacity-10 py-4 px-8 text-lg font-semibold text-black dark:border-white dark:border-opacity-10 dark:text-white"
>
Chat
</h3>
<div id="chat-window" class="relative w-full p-3 overflow-y-auto h-[14rem]">
<ul class="space-y-2">
<template
x-for="message in messages"
:key="message.id"
>
<div>
<template x-if="message.user_id == {{ Auth::user()->id }}">
<li class="flex justify-end">
<div class="relative max-w-xl px-4 py-2 text-black dark:text-white bg-gray-100 dark:bg-black rounded shadow">
<span class="block" x-text="message.body"></span>
</div>
</li>
</template>
<template x-if="message.user_id != {{ Auth::user()->id }}">
<li class="flex justify-start">
<div class="relative max-w-xl px-4 py-2 text-black dark:text-white bg-blue-100 dark:bg-[#1e2a78] rounded shadow">
<span class="block" x-text="message.body"></span>
</div>
</li>
</template>
</div>
</template>
</ul>
</div>
<div class="flex items-center justify-between w-full p-3 border-t border-gray-300">
<input
#keydown.enter="
#this.call('sendMessage', messageBody)
messageBody = ''
"
x-model="messageBody"
type="text"
placeholder="Message"
class="block w-full py-2 pl-4 mx-3 bg-gray-100 dark:bg-black rounded-full outline-none focus:text-gray-700 dark:focus:text-white dark:text-white"
name="message" required />
<button
#click="
#this.call('sendMessage', messageBody)
messageBody = ''
">
<svg class="w-5 h-5 text-black dark:text-white origin-center transform rotate-90" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20" fill="currentColor">
<path
d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z" />
</svg>
</button>
</div>
#error('messageBody')
<div class="w-full p-2 text-center">
<span class="text-red-500">Message is required!</span>
</div>
#enderror
</div>
<div
class="wow fadeInUp mb-10 rounded-md bg-light-bg dark:bg-dark"
data-wow-delay="0s">
<h3
class="border-b border-body-color border-opacity-10 py-4 px-8 text-lg font-semibold text-black dark:border-white dark:border-opacity-10 dark:text-white"
>
Active Players
</h3>
<ul class="flex flex-wrap py-6 px-8">
#forelse($here as $authData)
<li>
<a
href="javascript:void(0)"
class="text-body-color-3 mr-3 mb-3 inline-flex items-center justify-center rounded-full border-[.5px] border-body-color bg-body-color bg-opacity-10 py-2 px-4 hover:border-primary hover:bg-primary hover:text-white dark:border-[#363D68] dark:bg-[#272E5C] dark:text-white dark:hover:border-primary dark:hover:bg-primary dark:hover:text-white"
>
{{ $authData['name'] }}
</a>
</li>
#empty
#endforelse
</ul>
</div>
</div>
I figure it has to be something simple I am missing and hopefully someone can point me in the right direction.
EDIT to include Livewire code:
<?php
namespace App\Http\Livewire;
use App\Events\ChatSent;
use App\Models\Chat;
use App\Models\Games;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class Chatbox extends Component
{
public $game_id, $game, $chats;
public $here = [];
public $messages = [];
public function getListeners()
{
$game_id = $this->game_id;
return [
"echo-presence:chat.{$game_id},here" => 'here',
"echo-presence:chat.{$game_id},joining" => 'joining',
"echo-presence:chat.{$game_id},leaving" => 'leaving',
];
}
public function render()
{
return view('games.components.chatbox');
}
public function mount()
{
$this->game = Games::find($this->game_id);
$this->messages = Chat::
where('games_id', $this->game_id)
->with('user')
->latest()
->limit(30)
->get()
->reverse()
->values()
->toArray();
}
public function sendMessage($body)
{
if (! $body) {
$this->addError('messageBody', 'Message body is required.');
return;
}
$message = Auth::user()->chats()->create([
'body' => $body,
'games_id' => $this->game_id,
]);
$message->load('user');
broadcast(new ChatSent($message, $this->game))->toOthers();
$myMessage = $message->toArray();
$this->dispatchBrowserEvent('update-chat');
array_push($this->messages, $myMessage);
}
/**
* #param $message
*/
public function incomingMessage($message)
{
// get the hydrated model from incoming json/array.
$message = Chat::with('user')->find($message['id']);
array_push($this->messages, $message);
$this->dispatchBrowserEvent('update-chat');
}
/**
* #param $data
*/
public function here($data)
{
$this->here = $data;
}
/**
* #param $data
*/
public function leaving($data)
{
$here = collect($this->here);
$firstIndex = $here->search(function ($authData) use ($data) {
return $authData['id'] == $data['id'];
});
$here->splice($firstIndex, 1);
$this->here = $here->toArray();
}
/**
* #param $data
*/
public function joining($data)
{
$this->here[] = $data;
}
}

Laravel 8: Attempt to read property "id" on null

I am facing this error 'Attempt to read property "id" on null' in Laravel 8. It was working fine before but in my view I changed $user->id to $user->profile->id and now this is happening. I am logged in the app and I have changed my route accordingly to match profile id, I have also tried clearing cache etc.
Here is my Code:
User Model:
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* #var string[]
*/
// protected $fillable = [
// 'name',
// 'email',
// 'password',
// ];
protected $table = 'users';
protected $guarded = [];
/**
* The attributes that should be hidden for serialization.
*
* #var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
public function posts ()
{
return $this->hasMany(Post::class);
}
public function profile()
{
return $this->hasOne(Profile::class);
}
}
Profile Model:
class Profile extends Model
{
use HasFactory;
protected $table = 'profiles';
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
}
ProfilesController:
class ProfilesController extends Controller
{
public function show(User $user)
{
return view ('profiles.index', compact('user'));
}
public function edit(User $user)
{
return view ('profiles.index', compact('user'));
}
}
Route:
Route::get('profile/{profile}', [ProfilesController::class, 'show'])->middleware('auth');
Route::get('profile/{profile}/edit', [ProfilesController::class, 'edit'])->middleware('auth');
View:
<x-layout>
<section class="py-8 max-w-4xl mx-auto">
<h1 class="text-lg font-bold mb-8 pb-2 border-b">
#if ($user->id == auth()->user()->id)
Hello {{ $user->name }}, welcome to your profile.
#else
{{ $user->name }}'s Profile.
#endif
</h1>
<div class="flex">
<aside class="w-48 flex-shrink-0">
<h4 class="font-semibold mb-4">
Navigation
</h4>
<ul style="max-width: 75%">
<li>
View Profile
</li>
<li>
#if ($user->id == auth()->user()->id)
Edit Profile
#endif
</li>
</ul>
</aside>
<main class="flex-1">
<x-panel>
<div class="flex flex-col">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<div class="flex flex-row grid-cols-12">
<div class="flex flex-col col-span-4 row-span-full justify-items-start flex-grow-0 flex-shrink-0 grid-cols-4">
<div class="flex flex-row">
<img src="http://i.pravatar.cc/60?u={{ $user->profile->id }}" alt="" width="" height="" class="rounded-full h-24 w-24 flex m-2">
</div>
</div>
<div class="flex flex-col col-span-8 justify-right grid-cols-8 text-sm">
<div class="flex flex-row">
<div class="flex flex-col col-span-2 font-semibold">
<div class="pt-3">Name:</div>
<div class="pt-3">Email:</div>
<div class="pt-3">About:</div>
</div>
<div class="flex flex-col col-span-10">
<div class="pt-3 pl-4 text-justify">{{ $user->profile->name }}</div>
<div class="pt-3 pl-4 text-justify">{{ $user->profile->email }}</div>
<div class="pt-3 pl-4 text-justify"><p>{{ $user->profile->description }}</p></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</x-panel>
</main>
</div>
</section>
I think the problem is that you are passing a Profile model as indicated by your routes, but the method is looking for a User model.
Show and Edit have a User Model as a parameter. If you pass the Profile id, the method is gonna find the User model by id but with the id of the Profile model and not the user_id of the Profile model.
You will need to change the methods to:
public function show(Profile $profile)
{
$user = $profile->user;
return view ('profiles.index', compact('user'));
}
public function edit(Profile $profile)
{
$user = $profile->user;
return view ('profiles.index', compact('user'));
}
With this code the Profile model is found and via the relationship the User is obtained and passed to the view.
public function edit($id)
{
$table = Table::find($id);
return view('tables.edit', compact('table'));
}
public function update(Request $request, $id)
{
$table = Table::find($id);
$table->update($request->all());
return redirect('/tables');
}

Livewire doesn't show value from mutator

I'm trying to bind a date field (mydate) with laravel livewire. Basically I did the following:
In the model, I did a cast and created a mutator and an accessor:
<?php
namespace App\Models\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Platform extends Model
{
use HasFactory;
protected $fillable = ['name', 'mydate'];
protected $dates = ['created_at', 'updated_at', 'mydate'];
protected $casts = ['mydate' => 'datetime'];
public function getCreatedAtBrAttribute()
{
return optional($this->created_at)->format('d/m/Y H:i');
}
public function getUpdatedAtBrAttribute()
{
return optional($this->updated_at)->format('d/m/Y H:i');
}
public function getMydateBrAttribute()
{
return optional($this->mydate)->format('Y-m-d\TH:i');
}
public function setMydateBrAttribute($value)
{
$this->mydate = Carbon::parse($value)->format('Y-m-d H:i:s');
}
}
In the component I added the field in rules:
<?php
namespace App\Http\Livewire;
use App\Models\Models\Platform;
use Livewire\Component;
class PlatformForm extends Component
{
public Platform $platform;
protected $listeners = ['recordToEdit' => 'editPlatform', 'newRecord' => 'createPlatform'];
protected $rules = [
'platform.id' => 'sometimes',
'platform.name' => 'sometimes',
'platform.created_at' => 'sometimes',
'platform.updated_at' => 'sometimes',
'platform.mydate_br' => 'sometimes',
];
public function mount() {
$this->platform = $this->makeBlankPlatform();
}
public function makeBlankPlatform()
{
return Platform::make();
}
public function editPlatform(Platform $platform)
{
$this->platform = $platform;
}
public function createPlatform()
{
$this->platform = new Platform();
$this->platform->created_at = now();
}
public function save()
{
$this->platform->id
? $this->platform->updated_at = now()
: $this->platform->updated_at = $this->platform->created_at;
$this->platform->save();
$this->emit('refresh');
}
public function render()
{
return view('livewire.platform-form');
}
}
And in the view I added the wire:model, like this:
<div>
<div class="form-group">
<label for="name">Name</label>
<input wire:model.defer="platform.name" type="text" class="form-control">
</div>
<div class="form-group">
<label for="mydate_br">My date</label>
<input id="mydate_br" wire:model.defer="platform.mydate_br" type="text" class="form-control">
</div>
<div class="form-group">
<label for="created_at">Created at</label>
<input id="created_at" wire:model="platform.created_at_br" type="text" class="form-control" readonly>
</div>
<div class="form-group">
<label for="updated_at">Updated at</label>
<input id="updated_at" wire:model="platform.updated_at_br" type="text" class="form-control" readonly>
</div>
<hr class="border">
<div class="text-right">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancelar
</button>
<button wire:click="save" type="button" class="btn btn-primary" data-dismiss="modal">
Gravar
</button>
</div>
</div>
The problem is that the date stored in the database is not displayed in the input text, however, if I do it in the standard blade way, {{ $platform->mydate_br }}, the value is displayed, but here I lose functionality of livewire binding.
Anyone have a tip to help me resolve this?

Getting value to show up using livewire

I'm using laravel and livewire and I'm trying to create an edit page. What I'm trying to do is get the value to show up in the textbox.
So for example my edit page has product info that I'm trying to edit, but my product name isn't displaying in the textbox.
Here is my code
My ProductEdit.php
<?php
namespace Modules\Products\Http\Livewire;
use App\Models\Product;
use Livewire\Component;
class ProductsEdit extends Component
{
public $name;
public $product;
public function render()
{
return view('products::livewire.edit-products', [
'name' => $this->product->name
]);
}
public function updateProduct()
{
dd($this->name);
}
}
My edit-products.blade.php
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
id="product_name"
type="text"
name="product_name"
value="{{ $product->name }}"
wire:model="name"
>
</div>
<button wire:click="updateProduct" class="bg-green-400 hover:bg-green-300 text-green-800 font-bold py-2 px-4 rounded inline-flex items-center">Save</button>

Thymeleaf: processing inner elements

In my current spring-boot project, I have the follow thymeleaf processor:
public class Form extends AbstractProcessor {
public static Element form = new Element("form");
#Override
public ProcessorResult doProcess(Arguments arguments,ProcessorMatchingContext context,Node node) {
form.setProcessable(true);
form.setAttribute("role", "form");
form.setAttribute("class", "form");
form.setAttribute("action", "");
form.setAttribute("method", "post");
node.getParent().insertBefore(node, form);
List<Element> lista = node.getParent().getElementChildren();
for(Element child : lista) {
if(!child.getOriginalName().equals("form")) {
child.moveAllChildren(form);
}
}
node.getParent().removeChild(node);
return ProcessorResult.OK;
}
#Override
public int getPrecedence() {
return 0;
}
#Override
public IProcessorMatcher<? extends Node> getMatcher() {
return new ElementNameProcessorMatcher("form");
}
}
which handles this tag:
<form:form>
<field-box th:each="item : ${command.getClass().getDeclaredFields()}">
<div th:each="item2 : ${item.getDeclaredAnnotations()}">
<div th:switch="${item2.annotationType().getSimpleName()}">
<div th:case="'Checkbox'"><field:checkbox/></div>
<div th:case="'DataList'"><field:datalist/></div>
<div th:case="'Input'"><field:input/></div>
<div th:case="'Radiobutton'"><field:radio/></div>
<div th:case="'Select'"><field:select/></div>
<div th:case="'Textarea'"><field:textarea/></div>
</div>
</div>
</field-box>
<button type="submit" class="btn btn-default">Cadastrar</button>
<div id="yes" class="alert alert-success" role="alert" style="display: none;">
<button type="button" class="close" data-hide="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="text">Configuração salva com sucesso</span>
</div>
<div id="not" class="alert alert-danger" role="alert" style="display: none;">
<button type="button" class="close" data-hide="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="text"></span>
</div>
</form:form>
and generate this output:
<form role="form" class="form" action="" method="post">
<field-box th:each="item : ${command.getClass().getDeclaredFields()}">
<div th:each="item2 : ${item.getDeclaredAnnotations()}">
<div th:switch="${item2.annotationType().getSimpleName()}">
<div th:case="'Checkbox'"><field:checkbox></field:checkbox></div>
<div th:case="'DataList'"><field:datalist></field:datalist></div>
<div th:case="'Input'"><field:input></field:input></div>
<div th:case="'Radiobutton'"><field:radio></field:radio></div>
<div th:case="'Select'"><field:select></field:select></div>
<div th:case="'Textarea'"><field:textarea></field:textarea></div>
</div>
</div>
</field-box>
<button type="submit" class="btn btn-default">Cadastrar</button>
<div id="yes" class="alert alert-success" role="alert" style="display: none;">
<button type="button" class="close" data-hide="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="text">Configuração salva com sucesso</span>
</div>
<div id="not" class="alert alert-danger" role="alert" style="display: none;">
<button type="button" class="close" data-hide="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="text"></span>
</div>
</form>
as seen in the example above, the code it's not processing the elements inside the tag <form:form>. Anyone knows how to fix that?
Finally I found a solution for this issue. The final code for the processor class FormProcessor is that:
public class Form extends AbstractProcessor {
public static Element form = new Element("form");
#Override
public ProcessorResult doProcess(Arguments arguments,ProcessorMatchingContext context,Node node) {
form.setProcessable(true);
form.setAttribute("role", "form");
form.setAttribute("class", "form");
form.setAttribute("action", "");
form.setAttribute("method", "post");
node.getParent().insertBefore(node, form);
List<Element> lista = node.getParent().getElementChildren();
for(Element child : lista) {
if(!child.getOriginalName().equals("form")) child.moveAllChildren(form);
}
List<Element> lista2 = form.getElementChildren();
for(Element child : lista2) {
child.setProcessable(true);
}
node.getParent().removeChild(node);
return ProcessorResult.OK;
}
#Override
public int getPrecedence() {
return 0;
}
#Override
public IProcessorMatcher<? extends Node> getMatcher() {
return new ElementNameProcessorMatcher("form");
}
}

Resources