Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. // get a page
  4. $editpage = $pages->get("/editme/");
  5. $ignorefields = array("isOld","language_published");
  6.  
  7. $form = $modules->get("InputfieldForm");
  8. $form->method = 'post';
  9. $form->action = './';
  10.  
  11. // get the collection of inputs that can populate this page's fields
  12. $inputfields = $editpage->getInputfields();
  13.  
  14. // make all the fields required and add them to the form
  15. foreach($inputfields as $inputfield) {
  16. if(in_array($inputfield->name, $ignorefields)) continue;
  17. $form->add($inputfield);
  18. }
  19.  
  20. // the inputfields don't already have a submit button, so we'll add one.
  21. $submit = $modules->get("InputfieldSubmit");
  22. $submit->name = "submit";
  23. $submit->value = 'Submit';
  24.  
  25. // add the submit button the the form
  26. $form->add($submit);
  27.  
  28. $out = '';
  29.  
  30. // process the form
  31. if($this->input->post->submit) {
  32. // now we assume the form has been submitted.
  33. // tell the form to process input frmo the post vars.
  34. $form->processInput($this->input->post);
  35.  
  36. // see if any errors occurred
  37. if( count( $form->getErrors() )) {
  38. // re-render the form, it will include the error messages
  39. $out .= $form->render();
  40. } else {
  41. // successful form submission, so populate the page with the new values.
  42. $editpage->setOutputFormatting(false);
  43. foreach($form as $field) {
  44. $editpage->set($field->name, $field->value);
  45. }
  46. // save it
  47. $editpage->save();
  48. $out .= "Page saved.";
  49. $out .= $form->render();
  50. }
  51. } else {
  52. $out .= $form->render();
  53. }
  54.  
  55. include("head.inc"); // where scripts are added needed by the form
  56.  
  57. echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement