Template Forms + TabsNEW
1.7.32 Bootstrap theme
Fixed: using set_template() together with tabs or nested tables in tabs on the same form used to silently drop the tabs/nested content. A template can now also place tabs explicitly with a {tabs} placeholder.
HIDE CODE
<?php
$xcrud = Xcrud::get_instance();
$xcrud->table("orders");
$html_template = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customer Order Form</title>
<style>
/* Add your custom CSS styles here */
body {
font-family: Arial, sans-serif;
}
.order-form {
max-width: 600px;
margin: 0 auto;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 20px;
}
.form-label {
font-weight: bold;
}
.form-control {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.form-actions {
text-align: center;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="order-form">
<h2>Customer Order Form</h2>
<div class="form-group">
<label class="form-label">Customer Number:</label>
{customerNumber}
</div>
<div class="form-group">
<label class="form-label">Order Date:</label>
{orderDate}
</div>
<div class="form-group">
<label class="form-label">Status:</label>
{status}
</div>
<div class="form-group">
<label class="form-label">Required Date:</label>
{requiredDate}
</div>
<div class="form-group">
<label class="form-label">Shipped Date:</label>
{shippedDate}
</div>
<div class="form-actions">
{action}
</div>
</div>
</body>
</html>
';
$xcrud->change_type("status","select","",array("Not Shipped"=>"Not Shipped","Shipped"=>"Shipped","Completed"=>"Completed"));
// The save button is a virtual field (not a real orders column), so it must
// be explicitly added via fields() - like form_buttons.php does - or it
// never enters the field list and its template placeholder is left as-is.
$xcrud->fields("customerNumber,orderDate,status,requiredDate,shippedDate,action");
$xcrud->label("action","");
// create_field() (not change_type()) registers the button as a virtual/
// custom field, excluding it from the SQL SELECT - without this, xCrud
// tries to SELECT a real "orders.action" column and fails with a SQL error.
$xcrud->create_field("action","button","",array("href"=>"#","after"=>"edit","task"=>"save","icon"=>"fa fa-file","title"=>"Save My Form"));
$xcrud->set_attr("action",array("class"=>"btn btn-light xcrud-action","data-confirm"=>"Do you wish to save?"));
$xcrud->hide_button("save_edit");
$xcrud->hide_button("save_return");
$xcrud->hide_button("save_new");
$xcrud->set_template($html_template);
$xcrud->unset_remove(true,"orderNumber","=",10109);
echo $xcrud->render("edit",10109);
?>