コード例 #1
0
 /**
  * Request web form fields
  * @param string $url
  */
 private function requestWebFormFields($url)
 {
     $this->objApiRequest->setKey("api_url", $url);
     $objData = $this->objApiRequest->performListAction();
     //extract field elements
     foreach ($objData->data->arr_fields as $objField) {
         $objPredefinedField = new cls_form_element_predefined($objField);
         $objFormElement = new cls_form_element($objPredefinedField);
         $this->arr_form_elements[] = $objFormElement;
     }
     //end foreach
 }
コード例 #2
0
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// No direct access
defined('_JEXEC') or die;
/**
 * Load some classes
 */
require_once 'classes/cls_execute_request.php';
require_once 'classes/cls_forms.php';
require_once 'classes/cls_form_element.php';
require_once 'classes/cls_form_element_predefined.php';
/**
 * Gather params from module configuration
 */
$formid = $params->get('formid');
$form_css_enabled = $params->get("form_css_enabled");
$cache_form = $params->get('cache_form');
$cache_form_ttl = $params->get('cache_form_ttl');
$cache_path = "./tmp/form_cache_majestic_" . $formid . ".json";
//keep cached files out of public folders!
$arr_credentials = array('api_base_url' => $params->get('apiurl') . '/api', 'api_key' => $params->get('apikey'), 'api_username' => $params->get('apiusername'), 'api_password' => $params->get('apipassword'));
//load request object and set variables
$objExecuteRequest = new cls_execute_request();
//set variables loaded from config
$objExecuteRequest->setKeyFromArray($arr_credentials);
//set api url
$objExecuteRequest->setKey('api_url', $arr_credentials['api_base_url']);
require JModuleHelper::getLayoutPath('mod_majestic_forms', $params->get('layout', 'default'));
コード例 #3
0
/**
 * Deals with presenting and submitting forms
 */
function majestic_form()
{
    $api_url = get_option('m3_api_base_url');
    $api_key = get_option('m3_api_key');
    $api_user = get_option('m3_api_username');
    $api_pword = get_option('m3_api_password');
    $formid = get_option('m3_form_id');
    $form_css_enabled = get_option('m3_form_default_css');
    $cache_form = get_option('m3_cache_form');
    $cache_form_ttl = get_option('m3_cache_form_ttl');
    //set cache path
    if (!is_dir(getcwd() . '/wp-content/mjforms_tmp')) {
        if (is_writable(getcwd() . '/wp-content/mjforms_tmp/t.txt')) {
            mkdir(getcwd() . '/wp-content/mjforms_tmp', 0700);
        }
        //end if
    }
    //end if
    $cache_path = getcwd() . '/wp-content/mjforms_tmp/formcache' . $formid . '.json';
    $arr_credentials = array('api_base_url' => $api_url . '/api', 'api_key' => $api_key, 'api_username' => $api_user, 'api_password' => $api_pword);
    //load request object and set variables
    $objExecuteRequest = new cls_execute_request();
    //set variables load from credentials config file
    $objExecuteRequest->setKeyFromArray($arr_credentials);
    //set api url
    $objExecuteRequest->setKey('api_url', $arr_credentials['api_base_url']);
    try {
        //set initial api request values
        $objExecuteRequest->setKey('api_url', $arr_credentials['api_base_url']);
        //object is defined in mod_majestic_forms.php
        //load forms model
        $objForm = new cls_forms($objExecuteRequest);
        //generate the form
        $objForm = loadMajesticForm($objForm, $formid, array(), $arr_config = array('cache_form' => $cache_form, 'cache_form_ttl' => $cache_form_ttl, 'cache_path' => $cache_path));
        //set data to be populated into form where applicable, in this case only the post data is being used
        if ($_POST) {
            $arr_form_data = $_POST;
            //submit form data to the api
            $objForm->submitForm($arr_form_data);
        } else {
            //this array could be used to prepoulate form elements
            $arr_form_data = array();
        }
        //end if
        //generate form html
        $form_html = $objForm->generateOutput($arr_form_data);
        if ($form_css_enabled == 1) {
            //add some basic styling
            $form_html .= '
					<style>
						#' . $objForm->form_css_id . ' {
							padding: 5px;
							display: inline-block;
							margin-bottom: 25px;
							width: 500px;
						}

						#' . $objForm->form_css_id . ' div {
							margin: 5px 0px 5px 0px;
						}

						#' . $objForm->form_css_id . ' label.form-label  {
							display: inline-block;
							width: 150px;
						}
					</style>';
        }
        //end if
        //present the form
        echo $form_html;
    } catch (Exception $e) {
        echo '<fieldset><legend>Error:</legend>';
        echo '<pre>' . print_r($e, TRUE) . '</pre>';
        echo '</fieldset>';
    }
    //end catch
}