Re: trying to combine two forms into a single form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I believe this is it.  It is part of the mediawiki extension that I used as
a starting point for what I need it to do.  I am slowly getting better at
PHP, this was dropped into my lap and I don't have much experience yet with
PHP, I come from bash/sed/awk land.  This file is structuredinput.php, there
is only one more php file in the extension call specialstructuredinput.php
and I included that after this one as well.

Thanks


<?php

  error_reporting(0);

set_include_path(get_include_path() . PATH_SEPARATOR .
$IP.'/extensions/structuredInput/special' );

$StructuredInput = new StructuredInput();
$wgHooks['SpecialPage_initList'][] = array($StructuredInput,
'addToSpecialPages');
$wgHooks['EditPage::showEditForm:initial'][] = array($StructuredInput,
'editForm');

// Bootleg php namespace
class StructuredInput
{

  public static $inputList = array();

  function getInputList() {
    return StructuredInput::$inputList;
  }

  function addToSpecialPages(&$list) {
    global $wgAllMessagesEn;
        global $wgMessageCache;

    foreach (StructuredInput::getInputList() as $val) {
      $key = str_replace (' ', '', strtolower($val));
      if (!array_key_exists($key, $wgAllMessagesEn)) {
        $wgAllMessagesEn[$key] = $val;
        $wgMessageCache->addMessages( array ($key => $val) );

        $pageName = str_replace (' ', '', $val);

        $list[$pageName] = array('SpecialPage', $pageName);
      }
    }

    $wgAllMessagesEn['structuredinput'] = 'Structured Input Forms';
        $wgMessageCache->addMessages( array ('structuredinput' =>
'Structured Input Forms') );

    $list['StructuredInput'] = array('SpecialPage', 'StructuredInput');

    return true;
  }

  function editForm(&$form) {
    if (!empty($_POST['_type'])) {
      $post = $_POST;

require_once('structuredInput/transformations/'.$_POST['_type'].'.php');
      $form->textbox1 = $output;
      $form->starttime = wfTimestampNow();
      $form->edittime = wfTimestampNow();
    } elseif (empty($_GET['viewsource']) &&
strpos($form->mArticle->mContent, '<!--|StructuredInput|-->') !== False){
      global $wgServerName, $wgScriptPath;

      $inputType = str_replace(array('<','!','-','>'),
                               array('','','',''),

 $this->extractStructuredValue('StructuredInput',

 $form->mArticle->mContent)
                               );

      header('Location: http://
'.$wgServerName.$wgScriptPath.'/index.php?title=Special:'.$inputType.'&id='.$_GET['title']);
      die();
    }

        return true;
  }

  function extractStructuredValue($key, $haystack) {
    preg_match('/<!--\|'.$key.'\|-->(.*?)<!--\|'.$key.'\|-->/', $haystack,
$matches);

    if (!empty($matches)) {
      return $matches[1];
    } else {
      return '';
    }
  }

  function extractStructuredValues($haystack) {
    preg_match_all('/<!--\|(.*)\|-->(.*?)<!--\|\1\|-->/s', $haystack,
$matches);

    return array_combine($matches[1], $matches[2]);
  }

  function makeRadios($key, $data, $selectedValue) {
    $output = '';

    foreach ($data as $item) {
      $id = $key.str_replace(' ', '', $item['value']);

      if ($item['value'] == $selectedValue) {
        $selected = 'checked="checked"';
      } else {
        $selected = '';
      }

      $output .= <<<TEXT

        <input type="radio" id="$id" name="$key" value="{$item['value']}"
$selected />
        <label for="$id"><strong>{$item['value']}</strong>:
{$item['caption']}</label>
        <br />

TEXT;

    }

    return $output;
  }

  function makeSelect($key, $data, $selectedValue) {
    $output = '<select id="'.$key.'" name="'.$key.'">';
    foreach ($data as $value) {
      if ($value == $selectedValue) {
        $selected = ' selected="selected"';
      } else {
        $selected = '';
      }

      $output .= '<option'.$selected.'>'.$value.'</option>';
    }
    $output .= '</select>';
    return $output;
  }

  function getStructuredData($id) {
    $pageContent = Revision::newFromTitle( Title::newFromText($id)
)->getText();

    $data = StructuredInput::extractStructuredValues($pageContent);
    $data['_title'] = $id;

    return $data;
  }

}


________________________ NEW FILE ______________________

<?php


function wfSpecialStructuredInput() {

  global $wgOut, $wgServerName, $wgScriptPath;

  $structuredInputs = '';

  foreach (StructuredInput::getInputList() as $input) {
    $key = ucfirst(str_replace (' ', '', strtolower($input)));
    $structuredInputs .= '<li><a href="http://
'.$wgServerName.$wgScriptPath.'/index.php/Special:'.$key.'">'.$input.'</a></li>';
  }

  if (!empty($structuredInputs)) $structuredInputs =
'<ul>'.$structuredInputs.'</ul>';


  $wgOut->addHTML($structuredInputs);

}

?>





On Thu, Jun 9, 2011 at 11:10 AM, Jim Lucas <lists@xxxxxxxxx> wrote:

> On 6/9/2011 8:07 AM, matty jones wrote:
> > The two forms work fine by themselves, my issue is getting to two of them
> to
> > work with together, I don't even care if you need to upload the image
> > seperately from submitting the text data as long as it is all on the same
> > page.  Thanks for the thoughts on jQuerry, I will look into it.
> >
> > On Thu, Jun 9, 2011 at 10:53 AM, Jim Lucas <lists@xxxxxxxxx> wrote:
> >
> >> On 6/9/2011 5:37 AM, matty jones wrote:
> >>>         formEl.action += '&title=' + formEl['_title'].value;
> >>
> >> The only thing I see inconsistent is the above line.  But then again, it
> >> could
> >> be right.  You might be looking for $_GET['title'] in your processing
> page
> >> instead of $_GET['_title']
> >>
> >
>
> Can you show the PHP code that you use to process the form data text
> fields?
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux