Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // get a page
- $editpage = $pages->get("/editme/");
- $ignorefields = array("isOld","language_published");
- $form = $modules->get("InputfieldForm");
- $form->method = 'post';
- $form->action = './';
- // get the collection of inputs that can populate this page's fields
- $inputfields = $editpage->getInputfields();
- // make all the fields required and add them to the form
- foreach($inputfields as $inputfield) {
- if(in_array($inputfield->name, $ignorefields)) continue;
- $form->add($inputfield);
- }
- // the inputfields don't already have a submit button, so we'll add one.
- $submit = $modules->get("InputfieldSubmit");
- $submit->name = "submit";
- $submit->value = 'Submit';
- // add the submit button the the form
- $form->add($submit);
- $out = '';
- // process the form
- if($this->input->post->submit) {
- // now we assume the form has been submitted.
- // tell the form to process input frmo the post vars.
- $form->processInput($this->input->post);
- // see if any errors occurred
- if( count( $form->getErrors() )) {
- // re-render the form, it will include the error messages
- $out .= $form->render();
- } else {
- // successful form submission, so populate the page with the new values.
- $editpage->setOutputFormatting(false);
- foreach($form as $field) {
- $editpage->set($field->name, $field->value);
- }
- // save it
- $editpage->save();
- $out .= "Page saved.";
- $out .= $form->render();
- }
- } else {
- $out .= $form->render();
- }
- include("head.inc"); // where scripts are added needed by the form
- echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement