Original Source
https://pdocrud.com/demo/pages/insert
https://pdocrud.com/demo/pages/edit
https://pdocrud.com/demo/pages/view
https://pdocrud.com/demo/pages/send-email-using-pdocrud
https://pdocrud.com/demo/pages/fields-conditional-logic
https://pdocrud.com/demo/pages/field-validation
https://pdocrud.com/demo/pages/form-redirection
https://pdocrud.com/demo/pages/field-database-mapping
https://pdocrud.com/demo/pages/check-duplicate-before-insert
https://pdocrud.com/demo/pages/reset-form
https://pdocrud.com/demo/pages/password-encryption
https://pdocrud.com/demo/pages/multi-step-form
Insert Form
$pdocrud = new PDOCrud();
echo $pdocrud->dbTable("producttable")->render("insertform");
Form Edit Operation
$pdocrud = new PDOCrud();
$pdocrud->setPK("id");
echo $pdocrud->dbTable("orders")->render("EDITFORM",array("id" =>"58"));
Form View Operation
$pdocrud = new PDOCrud();
$pdocrud->setPK("id");
echo $pdocrud->dbTable("orders")->render("VIEWFORM",array("id" =>"58"));
Image Operations
With PDOCrud, you can easily resize images, make thumbnails, flip images, crop images, add overlay (watermark), or add text to images. You need to define the field type as image to make it file control. PDOCrud uses The SimpleImage PHP class to implement all these image related operations.
$pdocrud = new PDOCrud();
//resize image, (width as key and height as value in array)
$pdocrud->resizeImage(array("100"=>"100"));
//Add overlay image (watermark) - pass overlay image, position, opacity, x_position, y_position
$pdocrud->watermark("http://localhost/pdoCrud/demo/pages/images/overlay.png","bottom right","0.8");
// Thumbnail Trim the image and resize to exactly width and height given
$pdocrud->thumbnailImage(100, 100);
//Crop image - x1, y1, x2,y2
$pdocrud->crop(5, 20, 100, 400);
//flip image (x or y)
$pdocrud->flip("x");
//Add text on image
$pdocrud->imageText('Your Text', __DIR__.'/images/delicious.ttf', 32, '#FFFFFF', 'top', 0, 20);
$pdocrud->fieldTypes("product_image", "image");
$pdocrud->formFields(array("product_image","product_id"));
echo $pdocrud->dbTable("products")->render("insertform");
Multi Step Forms
You can design the form step wise also. You can show fields in different steps. It can be done using the jQuery tabs or jQuery stepy plugin.
$pdocrud = new PDOCrud();
$pdocrud->FormSteps(array("first_name", "last_name", "email", "phone", "gender","birth_date"), "General Info");
$pdocrud->FormSteps(array("user_name", "password"), "Login Details");
$pdocrud->FormSteps(array("address", "city", "state", "country", "zip_code"), "Address");
$pdocrud->FormSteps(array("hobbies", "educational_status", "about_yourself", "company_name"), "Other");
echo $pdocrud->dbTable("users")->render("insertform");
Password Encryption
You can define the encryption method to be used for password type fields before data insert or select. Previously you need to add callback function for this feature but now you can achieve same using this function also. Supported methods are base64_encode, md5 and sha1 with no extra parameters. If you need other way to encrypt, you can use the callback function.
$pdocrud = new PDOCrud();
$pdocrud->formFields(array("user_name","password"));
/**
* Sets the type of field
* @param string $fieldName field name for types needs to be set
* @param string $type Field type
* @param string $parameters Field parameters
* return object Object of class
*/
$pdocrud->fieldTypes("password", "password", array("encryption"=>"md5"));
echo $pdocrud->dbTable("users")->render("insertform");
Reset Form
You can automatically reset the form fields after form submission by specifying settings resetForm = true. You can pass it in constructor function or set it directly in config file.
//pass reset form true in constructor function or you can set it via config file
$pdocrud = new PDOCrud(false, "", "", array("resetForm" => true));
echo $pdocrud->dbTable("employee")->render("INSERTFORM");
Check Duplicate Records Form
If you want to check whether record with same value exists or not before inserting data, you can call checkDuplicateRecord() function to achieve it. It accepts array of fields that needs to be checked for duplicate record. For example, you can pass username and email in this function to check for duplicate record. It will return record already exists message if there is already field with same value exist.
$pdocrud = new PDOCrud();
$pdocrud->formFields(array("register_number","first_name","last_name","email"));
//Check for duplicate record. You can pass multiple fields also.
$pdocrud->checkDuplicateRecord(array("register_number"));
echo $pdocrud->dbTable("student")->render("insertform");
Database field mapping with static field
Many times you want to insert some static fixed value in database field along with the other field during database insert operation for example, you want to save logged in user id in the database table (saved in session etc) along with other fields that will be filled by user. User Id needs not to be changed by user and you want to save it's value so you can use this function to add static field value that will be saved in database. Please note that same thing can be done using the callback function also. you can show/hide the field like other static field and it can be viewed using the view source. So if it sensitive information than it will be better to use callback function.
$pdocrud = new PDOCrud();
// It uses same function formStaticFields that is used to add static fields
//first parameter is name of database field to be mapped, 2nd parameter is field type, 3rd parameter is value to be set, 4th parameter needs to be set "db"
$pdocrud->formStaticFields("customer_id_field", "hidden", array("33"),"db", "customer_id"); //add hidden field
echo $pdocrud->dbTable("ordertable")->render("insertform");
Redirect URL
Redirect to some specified URL after form submission.
$pdocrud = new PDOCrud();
$pdocrud->formRedirection("http://google.com");
echo $pdocrud->dbTable("orders")->render("insertform");
Field Validations
By default, field validations are generated as per the data type of field in database table. But you can also define extra validation on field, like max length, min length, url, equal to etc.
$pdocrud = new PDOCrud();
$pdocrud->formFields(array("user_name","email","password","confirm_password","phone"));
$pdocrud->fieldValidationType("user_name", "data-minlength", "10", "Please enter atleast 10 characters");
$pdocrud->fieldValidationType("password", "data-match", "confirm_password", "Password and confirm password not matching");
$pdocrud->formStaticFields("confirm_password", "text");
echo $pdocrud->dbTable("users")->render("insertform");
Conditional Logic
Conditional logic to show/hide some fields based on the value of field. Please note that this will work with the main table fields only. You can define for which value show some other fields or hide some other fields.
$pdocrud = new PDOCrud();
$pdocrud->fieldTypes("City", "select");//change state to select dropdown
$pdocrud->fieldDataBinding("City", array("Newyork"=>"Newyork","London"=>"London","Delhi"=>"Delhi","Other"=>"Other"), "", "","array");//add data using array in select dropdown
//when city is other then hide state and zip code else show
$pdocrud->fieldConditionalLogic("city", "Other", "=", "State", "hide");
$pdocrud->fieldConditionalLogic("city", "Other", "=", "Zip", "hide");
$pdocrud->fieldConditionalLogic("city", "Other", "!=", "State", "show");
$pdocrud->fieldConditionalLogic("city", "Other", "!=", "Zip", "show");
echo $pdocrud->dbTable("employee")->render("insertform");
Send Email Using Form
PDOCrud allows send form fields values added by user, to the email directly. You can formSendEmail function to define various email parameters. You can define message template or use the default template. Default template option allows you to send email with all fields in table format. You can define template for subject also. You can put filed name inside two curly braces. You can also insert and send email both by setting 5th parameter true.
$pdocrud = new PDOCrud();
$pdocrud->formFields(array("first_name","last_name","email","message"));
$subject = "Email from {{first_name}} {{last_name}}";
$message = "default_template";// this will display all fields in table format in email
//You can also define message new template as below
//$message = "first_name:{{first_name}}
last_name:{{last_name}}
message:{{message}}
";
$pdocrud->formSendEmail("info@pdocrud.com",array("someemail@gmail.com"),$subject,$message);
echo $pdocrud->setLangData("save", "Sign me up!")->dbTable("contact")->render("emailform");