process() public method

Processes forms, returns true on successful save
public process ( boolean $allow_partial_save = true, boolean $check_form_submit = true ) : boolean
$allow_partial_save boolean allows for partial form saving on failed validation
$check_form_submit boolean whether check for $_POST['submit_save']
return boolean whether processing was successful
Exemplo n.º 1
0
 /**
  * Test for FormDisplay::process
  *
  * @return void
  * @group medium
  */
 public function testProcess()
 {
     $this->assertFalse($this->object->process(true, true));
     $this->object = $this->getMockBuilder('PMA\\libraries\\config\\FormDisplay')->disableOriginalConstructor()->setMethods(array('save'))->getMock();
     $attrForms = new \ReflectionProperty('PMA\\libraries\\config\\FormDisplay', '_forms');
     $attrForms->setAccessible(true);
     $attrForms->setValue($this->object, array(1, 2, 3));
     $this->object->expects($this->once())->method('save')->with(array(0, 1, 2), false)->will($this->returnValue(true));
     $this->assertTrue($this->object->process(false, false));
     $attrForms->setValue($this->object, array());
     $this->assertFalse($this->object->process(false, false));
 }
Exemplo n.º 2
0
 foreach ($forms as $formset_id => $formset) {
     foreach ($formset as $form_name => $form) {
         $form_display->registerForm($formset_id . ': ' . $form_name, $form);
     }
 }
 $new_config = $cf->getFlatDefaultConfig();
 if (!empty($_POST['import_merge'])) {
     $new_config = array_merge($new_config, $cf->getConfigArray());
 }
 $new_config = array_merge($new_config, $config);
 $_POST_bak = $_POST;
 foreach ($new_config as $k => $v) {
     $_POST[str_replace('/', '-', $k)] = $v;
 }
 $cf->resetConfigData();
 $all_ok = $form_display->process(true, false);
 $all_ok = $all_ok && !$form_display->hasErrors();
 $_POST = $_POST_bak;
 if (!$all_ok && isset($_POST['fix_errors'])) {
     $form_display->fixErrors();
     $all_ok = true;
 }
 if (!$all_ok) {
     // mimic original form and post json in a hidden field
     include 'libraries/user_preferences.inc.php';
     $msg = Message::error(__('Configuration contains incorrect data for some fields.'));
     $msg->display();
     echo '<div class="config-form">';
     echo $form_display->displayErrors();
     echo '</div>';
     echo '<form action="prefs_manage.php" method="post">';
Exemplo n.º 3
0
/**
 * Processes forms registered in $form_display, handles error correction
 *
 * @param FormDisplay $form_display Form to display
 *
 * @return void
 */
function PMA_Process_formset(FormDisplay $form_display)
{
    if (isset($_GET['mode']) && $_GET['mode'] == 'revert') {
        // revert erroneous fields to their default values
        $form_display->fixErrors();
        PMA_generateHeader303();
    }
    if (!$form_display->process(false)) {
        // handle form view and failed POST
        echo $form_display->getDisplay(true, true);
        return;
    }
    // check for form errors
    if (!$form_display->hasErrors()) {
        PMA_generateHeader303();
        return;
    }
    // form has errors, show warning
    $separator = PMA_URL_getArgSeparator('html');
    $page = isset($_GET['page']) ? $_GET['page'] : null;
    $formset = isset($_GET['formset']) ? $_GET['formset'] : null;
    $formset = $formset ? "{$separator}formset={$formset}" : '';
    $formId = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null;
    if ($formId === null && $page == 'servers') {
        // we've just added a new server, get its id
        $formId = $form_display->getConfigFile()->getServerCount();
    }
    $formId = $formId ? "{$separator}id={$formId}" : '';
    ?>
    <div class="error">
        <h4><?php 
    echo __('Warning');
    ?>
</h4>
        <?php 
    echo __('Submitted form contains errors');
    ?>
<br />
        <a href="<?php 
    echo PMA_URL_getCommon(), $separator;
    ?>
page=<?php 
    echo $page, $formset, $formId, $separator;
    ?>
mode=revert">
            <?php 
    echo __('Try to revert erroneous fields to their default values');
    ?>
        </a>
    </div>
    <?php 
    echo $form_display->displayErrors();
    ?>
    <a class="btn" href="index.php<?php 
    echo PMA_URL_getCommon();
    ?>
">
        <?php 
    echo __('Ignore errors');
    ?>
    </a>
    &nbsp;
    <a class="btn" href="<?php 
    echo PMA_URL_getCommon() . $separator;
    ?>
page=<?php 
    echo $page . $formset . $formId . $separator;
    ?>
mode=edit">
        <?php 
    echo __('Show form');
    ?>
    </a>
    <?php 
}
Exemplo n.º 4
0
    // skip Developer form if no setting is available
    if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) {
        continue;
    }
    $form_display->registerForm($form_name, $form, 1);
}
if (isset($_POST['revert'])) {
    // revert erroneous fields to their default values
    $form_display->fixErrors();
    // redirect
    $url_params = array('form' => $form_param);
    PMA_sendHeaderLocation('./prefs_forms.php' . URL::getCommonRaw($url_params));
    exit;
}
$error = null;
if ($form_display->process(false) && !$form_display->hasErrors()) {
    // save settings
    $result = PMA_saveUserprefs($cf->getConfigArray());
    if ($result === true) {
        // reload config
        $GLOBALS['PMA_Config']->loadUserPreferences();
        $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
        $hash = ltrim($tabHash, '#');
        PMA_userprefsRedirect('prefs_forms.php', array('form' => $form_param), $hash);
        exit;
    } else {
        $error = $result;
    }
}
// display forms
$response = Response::getInstance();