WPBones
WPBones copied to clipboard
Add message to redirect
How to add message to redirects
heres my sample code
if($_POST!=null){
$p = $_POST;
$type = new Roomtype();
$type->name = $p['name'];
$type->price = $p['price'];
$type->maxpax = $p['maxpax'];
$type->children = $p['children'];
$type->adult = $p['adult'];
$type->details = $p['details'];
$type->save();
}
$this->redirect(get_admin_url().'admin.php?page=cdehotel_cde_roomtypes');
}
is there a way to do it like ?
return redirect('dashboard')->with('status', 'Profile updated!');
@paradis-A Hi, not yet, but interesting
@paradis-A Anyway, I think that you are already able to do the above flow easily.
You may check the demo branch of the WPKirk sample.
You will find an example of how to handle the POST in the View and Controller.
In short, in your case you could use the store method
<?php
namespace WPKirk\Http\Controllers\Dashboard;
use WPKirk\Http\Controllers\Controller;
class DashboardResourceController extends Controller
{
public function load()
{
if( $this->request->get( '_redirect' ) ) {
$this->redirect( $this->request->get( '_redirect' ) );
exit;
}
}
// GET
public function index() {
return WPKirk()->view( 'dashboard.optionsresview' )->with( 'method', 'GET' );
}
// POST
public function store() {
// process your own data and take nay action
if($_POST!=null){
$p = $_POST;
$type = new Roomtype();
$type->name = $p['name'];
$type->price = $p['price'];
$type->maxpax = $p['maxpax'];
$type->children = $p['children'];
$type->adult = $p['adult'];
$type->details = $p['details'];
$type->save();
}
// check the results and errors
// you may display the same view with new info
return WPKirk()->view( 'dashboard.optionsresview' )->with( 'status', 'Profile updated!');
// or you may display a completely different view or an error page
return WPKirk()->view( 'dashboard.your_view' )->with( 'status', 'Profile updated!');
// or you may display a completely different view or an error page - you may send any `$error` object/array with
// all useful information
return WPKirk()->view( 'dashboard.error' )->with( 'error', $error);
}
// PUT AND PATCH
public function update() {
return WPKirk()->view( 'dashboard.optionsresview' )->with( 'method', 'PUT AND PATCH' );
}
// DELETE
public function destroy() {
return WPKirk()->view( 'dashboard.optionsresview' )->with( 'method', 'DELETE' );
}
}
@paradis-A the above solution worked for you? have a look at https://wpbones.vercel.app/