ApPHP FormBuilder Advanced - Example of Code

Show Plain Text »
  1. <?php
  2. // include form builder class
  3. require_once 'formbuilder.php';
  4. // create class instance
  5. $form = new FB_Form('feedback');
  6.  
  7. // define form settings
  8. $form->AddHeader('<h1>Feedback Form</h1>')
  9.     ->SendResultAsEmail(1)
  10.     ->AddEmailAddress('hello@example.com')
  11.     ->AddEmailContent(date('H:i:s d-m-Y'))
  12.     ->SetEmailSubject('Feedback form result')
  13.     ->SetSuccessMsg('<div class="alert alert-success">Letter hass been sent!</div>')
  14.     ->SetFailureMsg('<div class="alert alert-error">Letter is not sent! Please check error fields.</div>');
  15.  
  16. // add field "Name"
  17. $form->AddTextField('feedback_name', 'Name')
  18.     ->IsAlphabetic()
  19.     ->AddAllowedSpecialCharacters('-', "'")
  20.     ->IsSpacesAllowed(1)
  21.     ->IsPointingAllowed(0)
  22.     ->IsRequired(1)
  23.     ->SetFieldSize(30)
  24.     ->SetPlaceholder('John Smith');
  25.  
  26. // add field "Email"
  27. $form->AddTextField('feedback_email', 'E-mail')
  28.     ->IsRequired(1)
  29.     ->IsEmail(1)
  30.     ->SetFieldSize(40)
  31.     ->SetPlaceholder('email@example.com');
  32.  
  33. // add field "Subject"    
  34. $form->AddTextField('feedback_subject', 'Subject')
  35.     ->SetMaxLength(1000);
  36.  
  37. // add field "Teaxarea"        
  38. $form->AddTextArea('feedback_text', 'Your message')
  39.     ->IsRequired(1)
  40.     ->SetCols(150)
  41.     ->SetRows(3)
  42.     ->SetMaxLength(10000);
  43.  
  44. // add Submission Button
  45. $form->AddSubmitButton('feedback_submit', 'Send');
  46.  
  47. // print form on the screen
  48. echo $form->GetHtml();  
  49. ?>