1. Go to this page and download the library: Download formpanel/formpanel-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
formpanel / formpanel-laravel example snippets
use Formpanel\Laravel\Facades\Formpanel;
// Submit form data using the default form slug from config
$result = Formpanel::submit([
'name' => 'John Doe',
'email' => '[email protected]',
'message' => 'Hello from Laravel!',
]);
echo "Submission ID: " . $result->id;
use Formpanel\Laravel\Facades\Formpanel;
// Get a client for a specific form
$client = Formpanel::form('contact-form');
// Submit data
$result = $client->submit([
'name' => 'Jane Doe',
'email' => '[email protected]',
'message' => 'Hello!',
]);
// Get form information
$form = $client->get();
echo "Form: {$form->name}";
echo "Fields: " . count($form->fields);
use Formpanel\FormClient;
class ContactController extends Controller
{
public function __construct(protected FormClient $formpanel)
{
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => ' } catch (\Formpanel\Exceptions\ValidationException $e) {
return redirect()->back()->withErrors($e->getErrors());
}
}
}
use Formpanel\Laravel\FormpanelFactory;
class FormController extends Controller
{
public function __construct(protected FormpanelFactory $formpanel)
{
}
public function submitContact(Request $request)
{
$client = $this->formpanel->make('contact-form');
$result = $client->submit($request->validated());
return redirect()->back()->with('success', 'Contact form submitted!');
}
public function submitNewsletter(Request $request)
{
$client = $this->formpanel->make('newsletter-signup');
$result = $client->submit(['email' => $request->email]);
return redirect()->back()->with('success', 'Subscribed to newsletter!');
}
}
namespace App\Http\Controllers;
use Formpanel\FormClient;
use Formpanel\Exceptions\ValidationException;
use Formpanel\Exceptions\FormpanelException;
use Illuminate\Http\Request;
class ContactController extends Controller
{
public function __construct(protected FormClient $formpanel)
{
}
public function create()
{
return view('contact');
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => ' ->withInput()
->withErrors($e->getErrors());
} catch (FormpanelException $e) {
// Other FormPanel errors
return redirect()
->back()
->withInput()
->with('error', 'Failed to submit form: ' . $e->getMessage());
}
}
}
namespace App\Jobs;
use Formpanel\Laravel\FormpanelFactory;
use Formpanel\Exceptions\FormpanelException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class SubmitFormToFormpanel implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
protected string $formSlug,
protected array $data
) {
}
public function handle(FormpanelFactory $factory): void
{
try {
$client = $factory->make($this->formSlug);
$result = $client->submit($this->data);
Log::info('Form submitted to FormPanel', [
'submission_id' => $result->id,
'form_slug' => $this->formSlug,
]);
} catch (FormpanelException $e) {
Log::error('Failed to submit form to FormPanel', [
'error' => $e->getMessage(),
'form_slug' => $this->formSlug,
]);
throw $e;
}
}
}