PHP Notice – yii\base\ErrorException
Array to string conversion
error shows to below line.
$row = Formdetail::findOneRow( “form_id = ‘{$form_id}’”, array( ) );
is there any idea to solve this…
PHP Notice – yii\base\ErrorException
Array to string conversion
error shows to below line.
$row = Formdetail::findOneRow( “form_id = ‘{$form_id}’”, array( ) );
is there any idea to solve this…
Cant guess your problem, But to fetch the row , try like this
// $form_id is the variable you have to pass
$row = Formdetail::findOne(['form_id' => $form_id]);
else , Refer This link . it helps you
No that line also not working,
my code is in below.Error line is in bold text.
[code]
<?php
namespace app\modules\WebForm\components\helpers;
use \stdClass;
use app\modules\WebForm\models\Formdetail;
use app\modules\WebForm\models\FormElementOptions;
use app\modules\WebForm\models\FormElements;
use app\modules\WebForm\models\FormValues;
use app\modules\WebForm\models\WebformSettings;
/**
Form Display Helper
FormDisplayHelper returns the Form with elments dynamically built by the user or raw form
*/
class FormDisplayHelper
{
/**Main function static to display a form
*There are few mode when displaying a form
*1. New blank form (form populated with default values)
*2. New form with error (displayed when 1 submitted and having error, form populated with user inputs)
*3. Edit form (form populated with data from db)
*4. Edit form with error (displayed when #3 submitted and having error)
*
* @access public
* @param string
* @param array()
* @param int
* @param array()
* @return str
*/
public static function display_webform_form( $image_url, $webform_lang, $form_id, $form_params = array( ) )
{
$ul_class = '';
$pagination_header = '';
$payment_total_markup_top = '';
$custom_element = '';
$payment_total_markup_bottom = '';
$form_resume_markup = '';
$button_markup = '';
$form_enc_type = '';
$range_limit_markup = '';
$button_secondary_markup = '';
$page_number = ( isset( $form_params[ 'page_number' ] ) ) ? $form_params[ 'page_number' ] : '1';
$populated_values = ( isset( $form_params[ 'populated_values' ] ) ) ? $form_params[ 'populated_values' ] : array( );
$error_elements = ( isset( $form_params[ 'error_elements' ] ) ) ? $form_params[ 'error_elements' ] : array( );
$custom_error = ( isset( $form_params[ 'custom_error' ] ) ) ? $form_params[ 'custom_error' ] : '';
$edit_id = ( isset( $form_params[ 'edit_id' ] ) ) ? (int) $form_params[ 'edit_id' ] : 0;
$integration_method = ( isset( $form_params[ 'integration_method' ] ) ) ? $form_params[ 'integration_method' ] : ''; //valid values are empty string, 'iframe' or 'php','phone'
$machform_path = ( !empty( $form_params[ 'machform_path' ] ) ) ? $form_params[ 'machform_path' ] : '';
$machform_data_path = ( !empty( $form_params[ 'machform_data_path' ] ) ) ? $form_params[ 'machform_data_path' ] : '';
//if there is custom error, don't show other errors
if ( !empty( $custom_error ) ) {
$error_elements = array( );
}
//get form properties data
[b][b]$row = Formdetail::findOneRow("form_id ='{$form_id}'",array());[/b][/b]
//check for non-existent or currently drafted forms
if ( empty( $row ) || $row->form_active != 1 ) {
die( 'This is not valid form URL.' );
}
$form = new stdClass();
if ( count( $row ) > 0 ) {
$form->error_message = '';
$form->id = $form_id;
$form->name = $row->form_name;
$form->description = $row->form_description;
$form->redirect = $row->form_redirect;
$form->success_message = $row->form_success_message;
$form->password = $row->form_password;
$form->frame_height = $row->form_frame_height;
$form->unique_ip = $row->form_unique_ip;
$form->has_css = $row->form_has_css;
$form->active = $row->form_active;
$form->captcha = $row->form_captcha;
$form->captcha_type = $row->form_captcha_type;
$form->review = $row->form_review;
$form->label_alignment = $row->form_label_alignment;
$form->page_total = $row->form_page_total;
$form->lastpage_title = $row->form_lastpage_title;
$form->submit_primary_text = $row->form_submit_primary_text;
$form->submit_secondary_text = $row->form_submit_secondary_text;
$form->submit_primary_img = $row->form_submit_primary_img;
$form->submit_secondary_img = $row->form_submit_secondary_img;
$form->submit_use_image = (int) $row->form_submit_use_image;
$form->pagination_type = $row->form_pagination_type;
$form->review_primary_text = $row->form_review_primary_text;
$form->review_secondary_text = $row->form_review_secondary_text;
$form->review_primary_img = $row->form_review_primary_img;
$form->review_secondary_img = $row->form_review_secondary_img;
$form->review_use_image = (int) $row->form_review_use_image;
$form->review_title = $row->form_review_title;
$form->review_description = $row->form_review_description;
$form->resume_enable = $row->form_resume_enable;
$form->theme_id = (int) $row->form_theme_id;
$form->payment_show_total = (int) $row->payment_show_total;
$form->payment_total_location = $row->payment_total_location;
$form->payment_enable_merchant = ( (int) $row->payment_enable_merchant < 1 ) ? '0' : (int) $row->payment_enable_merchant;
$form->payment_currency = $row->payment_currency;
$form->payment_price_type = $row->payment_price_type;
$form->payment_price_amount = $row->payment_price_amount;
$form->limit_enable = (int) $row->form_limit_enable;
$form->limit = (int) $row->form_limit;
$form->schedule_enable = (int) $row->form_schedule_enable;
$form->schedule_start_date = $row->form_schedule_start_date;
$form->schedule_end_date = $row->form_schedule_end_date;
$form->schedule_start_hour = $row->form_schedule_start_hour;
$form->schedule_end_hour = $row->form_schedule_end_hour;
$form->language = ( !empty( $form->language ) ) ? LanguageHelper::set_language( trim( $row->form_language ) ) : LanguageHelper::set_language();
$form->is_error = empty( $error_elements ) ? '0' : '1';
if ( ( !empty( $edit_id ) ) )
$form->active = 1;
}
//get elements data
//get element options first and store it into array
$form_element_options = FormElementsOptions::findAllRow( "form_id = '{$form_id}' and live=1 order by element_id asc,position asc", array( ) );
$options_lookup = array( );
if ( count( $form_element_options ) > 0 ) {
foreach ( $form_element_options as $row ) {
$element_id = $row->element_id;
$option_id = $row->option_id;
$options_lookup[ $element_id ][ $option_id ][ 'position' ] = $row->position;
$options_lookup[ $element_id ][ $option_id ][ 'option' ] = $row->option;
$options_lookup[ $element_id ][ $option_id ][ 'option_is_default' ] = $row->option_is_default;
if ( isset( $element_prices_array[ $element_id ][ $option_id ] ) ) {
$options_lookup[ $element_id ][ $option_id ][ 'price_definition' ] = $element_prices_array[ $element_id ][ $option_id ];
}
}
}
$matrix_elements = array( );
//get elements data
$element = array( );
$page_number_clause = ( $page_number === 0 ) ? '' : "and element_page_number = '{$page_number}'";
$form_elements = FormElements::findAllRow( "form_id = '{$form_id}' and element_status='1' {$page_number_clause} and element_type <> 'page_break' ORDER BY element_position asc", array( ) );
$j = 0;
$has_calendar = false; //assume the form doesn't have calendar, so it won't load calendar.js
$has_advance_uploader = false;
$has_guidelines = false;
if ( count( $form_elements ) > 0 ) {
foreach ( $form_elements as $row ) {
$element[ $j ] = new stdClass();
$element_id = $row->element_id;
$element_type = $row->element_type;
//lookup element options first
if ( !empty( $options_lookup[ $element_id ] ) ) {
$element_options = array( );
$i = 0;
foreach ( $options_lookup[ $element_id ] as $option_id => $data ) {
$element_options[ $i ] = new stdClass();
$element_options[ $i ]->id = $option_id;
$element_options[ $i ]->option = $data[ 'option' ];
$element_options[ $i ]->is_default = $data[ 'option_is_default' ];
$element_options[ $i ]->is_db_live = 1;
if ( isset( $data[ 'price_definition' ] ) ) {
$element_options[ $i ]->price_definition = $data[ 'price_definition' ];
}
$i++;
}
}
$element[ $j ]->title = nl2br( $row->element_title );
$element[ $j ]->instructions = $row->element_instructions;
if ( !empty( $row->element_guidelines ) && ( $element_type != 'section' ) && ( $element_type != 'matrix' ) ) {
$has_guidelines = true;
}
$element[ $j ]->size = $row->element_size;
$element[ $j ]->is_required = $row->element_is_required;
$element[ $j ]->is_unique = $row->element_is_unique;
$element[ $j ]->is_private = $row->element_is_private;
$element[ $j ]->type = $element_type;
$element[ $j ]->position = $row->element_position;
$element[ $j ]->id = $element_id;
$element[ $j ]->is_db_live = 1;
$element[ $j ]->form_id = $form_id;
$element[ $j ]->choice_has_other = (int) $row->element_choice_has_other;
$element[ $j ]->choice_other_label = $row->element_choice_other_label;
$element[ $j ]->choice_columns = (int) $row->element_choice_columns;
$element[ $j ]->time_showsecond = (int) $row->element_time_showsecond;
$element[ $j ]->time_24hour = (int) $row->element_time_24hour;
$element[ $j ]->address_hideline2 = (int) $row->element_address_hideline2;
$element[ $j ]->address_us_only = (int) $row->element_address_us_only;
$element[ $j ]->date_enable_range = (int) $row->element_date_enable_range;
$element[ $j ]->date_range_min = $row->element_date_range_min;
$element[ $j ]->date_range_max = $row->element_date_range_max;
$element[ $j ]->date_enable_selection_limit = (int) $row->element_date_enable_selection_limit;
$element[ $j ]->date_selection_max = (int) $row->element_date_selection_max;
$element[ $j ]->date_disable_past_future = (int) $row->element_date_disable_past_future;
$element[ $j ]->date_past_future = $row->element_date_past_future;
$element[ $j ]->date_disable_weekend = (int) $row->element_date_disable_weekend;
$element[ $j ]->date_disable_specific = (int) $row->element_date_disable_specific;
$element[ $j ]->date_disabled_list = $row->element_date_disabled_list;
$element[ $j ]->file_enable_type_limit = (int) $row->element_file_enable_type_limit;
$element[ $j ]->file_block_or_allow = $row->element_file_block_or_allow;
$element[ $j ]->file_type_list = $row->element_file_type_list;
$element[ $j ]->file_as_attachment = (int) $row->element_file_as_attachment;
$element[ $j ]->file_enable_advance = (int) $row->element_file_enable_advance;
if ( !empty( $element[ $j ]->file_enable_advance ) ) {
$has_advance_uploader = true;
$element[ $j ]->is_design_mode = false;
}
$element[ $j ]->file_auto_upload = (int) $row->element_file_auto_upload;
$element[ $j ]->file_enable_multi_upload = (int) $row->element_file_enable_multi_upload;
$element[ $j ]->file_max_selection = (int) $row->element_file_max_selection;
$element[ $j ]->file_enable_size_limit = (int) $row->element_file_enable_size_limit;
$element[ $j ]->file_size_max = (int) $row->element_file_size_max;
$element[ $j ]->matrix_allow_multiselect = (int) $row->element_matrix_allow_multiselect;
$element[ $j ]->matrix_parent_id = (int) $row->element_matrix_parent_id;
$element[ $j ]->upload_dir = ''; //$mf_settings['upload_dir'];
$element[ $j ]->range_min = $row->element_range_min;
$element[ $j ]->range_max = $row->element_range_max;
$element[ $j ]->range_limit_by = $row->element_range_limit_by;
$element[ $j ]->css_class = $row->element_css_class;
$element[ $j ]->machform_path = $machform_path;
$element[ $j ]->machform_data_path = $machform_data_path;
//this data came from db or form submit
//being used to display edit form or redisplay form with errors and previous inputs
//this should be optimized in the future, only pass necessary data, not the whole array
$element[ $j ]->populated_value = $populated_values;
//set prices for price-enabled field
if ( $element_type == 'money' && isset( $element_prices_array[ $element_id ][ 0 ] ) ) {
$element[ $j ]->price_definition = 0;
}
//if there is file upload type, set form enctype to multipart
if ( $element_type == 'file' ) {
$form_enc_type = 'enctype="multipart/form-data"';
//if this is multipage form
if ( ( $form->page_total > 1 && !empty( $populated_file_values ) ) ) {
//populate the default value for uploaded files, when validation error occured
//make sure to keep the file token if exist
if ( !empty( $populated_values[ 'element_' . $element_id ][ 'file_token' ] ) ) {
$populated_file_values[ 'element_' . $element_id ][ 'file_token' ] = $populated_values[ 'element_' . $element_id ][ 'file_token' ];
}
$element[ $j ]->populated_value = $populated_file_values;
}
}
if ( !empty( $error_elements[ $element[ $j ]->id ] ) ) {
$element[ $j ]->is_error = 1;
$element[ $j ]->error_message = $error_elements[ $element[ $j ]->id ];
}
$element[ $j ]->default_value = htmlspecialchars( $row->element_default_value );
$element[ $j ]->constraint = $row->element_constraint;
if ( !empty( $element_options ) ) {
$element[ $j ]->options = $element_options;
} else {
$element[ $j ]->options = '';
}
//if the element is a matrix field and not the parent, store the data into a lookup array for later use when rendering the markup
if ( $element_type == 'matrix' && !empty( $row->element_matrix_parent_id ) ) {
$parent_id = $row->element_matrix_parent_id;
$el_position = $row->element_position;
$matrix_elements[ $parent_id ][ $el_position ][ 'title' ] = $element[ $j ]->title;
$matrix_elements[ $parent_id ][ $el_position ][ 'id' ] = $element[ $j ]->id;
$matrix_child_option_id = '';
foreach ( $element_options as $value ) {
$matrix_child_option_id .= $value->id . ',';
}
$matrix_child_option_id = rtrim( $matrix_child_option_id, ',' );
$matrix_elements[ $parent_id ][ $el_position ][ 'children_option_id' ] = $matrix_child_option_id;
//remove it from the main element array
$element[ $j ] = array( );
unset( $element[ $j ] );
$j--;
}
$j++;
}
}
//generate html markup for each element
$container_class = '';
$all_element_markup = '';
if ( count( $element ) > 0 ) {
foreach ( $element as $element_data ) {
if ( $element_data->is_private && empty( $edit_id ) ) { //don't show private element on live forms
continue;
}
//if this is matrix field, build the children data from $matrix_elements array
if ( $element_data->type == 'matrix' ) {
$element_data->matrix_children = isset( $matrix_elements[ $element_data->id ] ) ? $matrix_elements[ $element_data->id ] : '';
}
$all_element_markup .= call_user_func( 'ElementHelper::display_webform_' . $element_data->type, $image_url, $webform_lang, $element_data, true );
}
}
if ( !empty( $custom_error ) ) {
$form->error_message = <<<EOT
<li id="error_message">
<h3 id="error_message_title">{$custom_error}</h3>
</li>
EOT;
} elseif ( !empty( $error_elements ) ) {
$form->error_message = <<<EOT
<li id="error_message">
<h3 id="error_message_title">{$webform_lang['error_title']}</h3>
<p id="error_message_desc">{$webform_lang['error_desc']}</p>
</li>
EOT;
}
$field_highlight_color = '#FFF7C0';
$form_container_class = empty( $integration_method ) ? 'WarpShadow WLarge WNormal' : '';
if ( empty( $form->review ) ) {
if ( $form->submit_use_image == 0 ) {
$submit_button_markup = '<input id="submit_form" class="button_text" type="submit" name="submit_form" value="' . $form->submit_primary_text . '" />';
} else {
$submit_button_markup = '<input id="submit_form" class="button_text" type="image" name="submit_form" src = "' . $form->submit_primary_img . '" value="' . $form->submit_primary_text . '" />';
}
} else {
$submit_button_markup = '<input id="submit_form" class="button_text" type="submit" name="submit_form" value="' . $webform_lang[ 'continue_button' ] . '" />';
}
//display edit_id if there is any, this is being called on edit_entry.php page
if ( !empty( $edit_id ) ) {
$edit_markup = "<input type=\"hidden\" name=\"edit_id\" value=\"{$edit_id}\" />\n";
$submit_button_markup = '<input id="submit_form" class="button_text" type="submit" name="submit_form" value="Save Changes" />';
} else {
$edit_markup = '';
}
//check for specific form css, if any, use it instead
if ( $form->has_css ) {
$css_dir = $mf_settings[ 'data_dir' ] . "/form_{$form_id}/css/";
}
if ( !empty( $form->password ) && empty( $_SESSION[ 'user_authenticated' ] ) ) { //if form require password and password hasn't set yet
$show_password_form = true;
} elseif ( !empty( $form->password ) && !empty( $_SESSION[ 'user_authenticated' ] ) && $_SESSION[ 'user_authenticated' ] != $form_id ) { //if user authenticated but not for this form
$show_password_form = true;
} else { //user authenticated for this form, or no password required
$show_password_form = false;
}
if ( $show_password_form ) {
$submit_button_markup = '<input id="submit_form" class="button_text" type="submit" name="submit_form" value="' . $webform_lang[ 'submit_button' ] . '" />';
}
//default markup for single page form submit button
$button_markup = <<<EOT
<li id="li_buttons" class="buttons">
<input type="hidden" name="form_id" value="{$form->id}" />
{$edit_markup}
<input type="hidden" name="submit_form" value="1" />
<input type="hidden" name="page_number" value="{$page_number}" />
{$submit_button_markup}
</li>
EOT;
//check for form limit rule
$form_has_maximum_entries = false;
//check for automatic scheduling limit, if enabled
if ( !empty( $form->schedule_enable ) ) {
$schedule_start_time = strtotime( $form->schedule_start_date . ' ' . $form->schedule_start_hour );
$schedule_end_time = strtotime( $form->schedule_end_date . ' ' . $form->schedule_end_hour );
$current_time = strtotime( date( "Y-m-d H:i:s" ) );
if ( !empty( $schedule_start_time ) ) {
if ( $current_time < $schedule_start_time ) {
$form->active = 0;
}
}
if ( !empty( $schedule_end_time ) ) {
if ( $current_time > $schedule_end_time ) {
$form->active = 0;
}
}
}
if ( empty( $form->active ) || $form_has_maximum_entries ) { //if form is not active, don't show the fields
$form_desc_div = '';
$all_element_markup = '';
$button_markup = '';
$ul_class = 'class="password"';
if ( $form_has_maximum_entries ) {
$inactive_message = $webform_lang[ 'form_limited' ];
} else {
$inactive_message = $webform_lang[ 'form_inactive' ];
}
$custom_element = <<<EOT
<li>
<h2>{$inactive_message}</h2>
</li>
EOT;
} else {
if ( !empty( $form->name ) || !empty( $form->description ) ) {
$form->description = nl2br( $form->description );
$form_desc_div = <<<EOT
<div class="form_description">
<h2>{$form->name}</h2>
<p>{$form->description}</p>
</div>
EOT;
}
}
if ( !$has_guidelines ) {
$container_class .= " no_guidelines";
}
if ( $integration_method == 'iframe' ) {
$html_class_tag = 'class="embed"';
}
//if the form has multiple pages
//display the pagination header
if ( $form->page_total > 1 && $show_password_form === false ) {
//build pagination header based on the selected type. possible values:
//steps - display multi steps progress
//percentage - display progress bar with percentage
//disabled - disabled
$page_breaks_data = array( );
$page_title_array = array( );
//get page titles
$form_elements = null;
$form_elements = FormElements::findAllRow( "form_id = '{$form_id}' and element_status = 1 and element_type = 'page_break' ORDER BY element_page_number asc", array( ) );
if ( count( $form_elements ) > 0 ) {
foreach ( $form_elements as $row ) {
$temp_page_number = $row[ 'element_page_number' ];
$page_breaks_data[ $temp_page_number ][ 'use_image' ] = $row->element_submit_use_image;
$page_breaks_data[ $temp_page_number ][ 'primary_text' ] = $row->element_submit_primary_text;
$page_breaks_data[ $temp_page_number ][ 'secondary_text' ] = $row->element_submit_secondary_text;
$page_breaks_data[ $temp_page_number ][ 'primary_img' ] = $row->element_submit_primary_img;
$page_breaks_data[ $temp_page_number ][ 'secondary_img' ] = $row->element_submit_secondary_img;
$page_title_array[ ] = $row->element_page_title;
}
}
//add the last page buttons info into the array for easy lookup
$page_breaks_data[ $form->page_total ][ 'use_image' ] = $form->submit_use_image;
$page_breaks_data[ $form->page_total ][ 'primary_text' ] = $form->submit_primary_text;
$page_breaks_data[ $form->page_total ][ 'secondary_text' ] = $form->submit_secondary_text;
$page_breaks_data[ $form->page_total ][ 'primary_img' ] = $form->submit_primary_img;
$page_breaks_data[ $form->page_total ][ 'secondary_img' ] = $form->submit_secondary_img;
if ( $form->pagination_type == 'steps' ) {
$page_titles_markup = '';
$i = 1;
foreach ( $page_title_array as $page_title ) {
if ( $i == $page_number ) {
$ap_tp_num_active = ' ap_tp_num_active';
$ap_tp_text_active = ' ap_tp_text_active';
} else {
$ap_tp_num_active = '';
$ap_tp_text_active = '';
}
$page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num' . $ap_tp_num_active . '">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text' . $ap_tp_text_active . '">' . $page_title . '</span></td><td align="center" class="ap_tp_arrow">&gt;</td>' . "\n";
$i++;
}
//add the last page title into the pagination header markup
if ( $i == $page_number ) {
$ap_tp_num_active = ' ap_tp_num_active';
$ap_tp_text_active = ' ap_tp_text_active';
} else {
$ap_tp_num_active = '';
$ap_tp_text_active = '';
}
$page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num' . $ap_tp_num_active . '">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text' . $ap_tp_text_active . '">' . $form->lastpage_title . '</span></td>';
//if form review enabled, we need to add the pagination header
if ( !empty( $form->review ) ) {
$i++;
$page_titles_markup .= '<td align="center" class="ap_tp_arrow">&gt;</td><td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $form->review_title . '</span></td>';
}
$pagination_header = <<<EOT
<li id="pagination_header" class="li_pagination">
<table class="ap_table_pagination" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
{$page_titles_markup}
</tr>
</table>
</li>
EOT;
} else if ( $form->pagination_type == 'percentage' ) {
$page_total = count( $page_title_array ) + 1;
if ( !empty( $form->review ) ) {
$page_total++;
}
$percent_value = round( ( $page_number / $page_total ) * 100 );
if ( $percent_value == 100 ) { //it's not make sense to display 100% when the form is not really submitted yet
$percent_value = 99;
}
if ( !empty( $form->review ) ) {
if ( ( $page_total - 1 ) == $page_number ) { //if this is last page of the form
$current_page_title = $form->lastpage_title;
} else {
$current_page_title = $page_title_array[ $page_number - 1 ];
}
} else {
if ( $page_total == $page_number ) { //if this is last page of the form
$current_page_title = $form->lastpage_title;
} else {
$current_page_title = $page_title_array[ $page_number - 1 ];
}
}
$page_number_title = sprintf( $webform_lang[ 'page_title' ], $page_number, $page_total );
$pagination_header = <<<EOT
<li id="pagination_header" class="li_pagination" title="Click to edit">
<h3 id="page_title_{$page_number}">{$page_number_title} - {$current_page_title}</h3>
<div class="mf_progress_container">
<div id="mf_progress_percentage" class="mf_progress_value" style="width: {$percent_value}%"><span>{$percent_value}%</span></div>
</div>
</li>
EOT;
} else {
$pagination_header = '';
}
//build the submit buttons markup
if ( empty( $edit_id ) ) {
if ( empty( $page_breaks_data[ $page_number ][ 'use_image' ] ) ) { //if using text buttons as submit
if ( $page_number > 1 ) {
$button_secondary_markup = '<input class="button_text btn_secondary" type="submit" id="submit_secondary" name="submit_secondary" value="' . $page_breaks_data[ $page_number ][ 'secondary_text' ] . '" />';
}
$button_markup = <<<EOT
<li id="li_buttons" class="buttons">
<input type="hidden" name="form_id" value="{$form->id}" />
{$edit_markup}
<input type="hidden" name="submit_form" value="1" />
<input type="hidden" name="page_number" value="{$page_number}" />
<input class="button_text btn_primary" type="submit" id="submit_primary" name="submit_primary" value="{$page_breaks_data[$page_number]['primary_text']}" />
{$button_secondary_markup}
</li>
EOT;
} else { //if using images as submit
if ( $page_number > 1 ) {
$button_secondary_markup = '<input class="submit_img_secondary" type="image" alt="Previous" id="submit_secondary" name="submit_secondary" src="' . $page_breaks_data[ $page_number ][ 'secondary_img' ] . '" />';
}
$button_markup = <<<EOT
<li id="li_buttons" class="buttons">
<input type="hidden" name="form_id" value="{$form->id}" />
{$edit_markup}
<input type="hidden" name="submit_form" value="1" />
<input type="hidden" name="page_number" value="{$page_number}" />
<input class="submit_img_primary" type="image" alt="Continue" id="submit_primary" name="submit_primary" src="{$page_breaks_data[$page_number]['primary_img']}" />
{$button_secondary_markup}
</li>
EOT;
}
} else { //if there is edit_id, then this is edit_entry page, display a standard button
$button_markup = <<<EOT
<li id="li_buttons" class="buttons">
<input type="hidden" name="form_id" value="{$form->id}" />
{$edit_markup}
<input type="hidden" name="submit_form" value="1" />
<input type="hidden" name="page_number" value="{$page_number}" />
<input class="button_text btn_primary" type="submit" id="submit_primary" name="submit_primary" value="Save Changes" />
</li>
EOT;
}
}
//if the form has resume enabled and this is multi page form (single page form doesn't have resume option)
if ( !empty( $form->resume_enable ) && $form->page_total > 1 ) {
if ( !empty( $error_elements[ 'element_resume_email' ] ) ) {
$li_resume_email_style = '';
$li_resume_error_message = "<p class=\"error\">{$error_elements['element_resume_email']}</p>";
$li_resume_class = 'class="error"';
$li_resume_checked = 'checked="checked"';
$li_resume_button_status = 1;
} else {
$li_resume_email_style = 'style="display: none"';
$li_resume_error_message = '';
$li_resume_class = '';
$li_resume_checked = '';
$li_resume_button_status = 0;
}
$form_resume_markup = <<<EOT
<li id="li_resume_checkbox">
<div>
<span><input type="checkbox" value="1" class="element checkbox" name="element_resume_checkbox" id="element_resume_checkbox" {$li_resume_checked}>
<label for="element_resume_checkbox" class="om_choice">{$webform_lang['resume_checkbox_title']}</label>
</span>
</div>
</li>
<li id="li_resume_email" {$li_resume_class} {$li_resume_email_style} data-resumebutton="{$li_resume_button_status}" data-resumelabel="{$webform_lang['resume_submit_button_text']}">
<label for="element_resume_email" class="description">{$webform_lang['resume_email_input_label']}</label>
<div>
<input type="text" value="{$populated_values['element_resume_email']}" class="element text om_medium" name="element_resume_email" id="element_resume_email">
</div><p id="guide_resume_email" class="guidelines"><small>{$webform_lang['resume_guideline']}</small></p> {$li_resume_error_message}
</li>
EOT;
}
//if the form has enabled merchant support and set the total payment to be displayed
if ( !empty( $form->payment_enable_merchant ) && !empty( $form->payment_show_total ) ) {
$currency_symbol = '$';
switch ( $form->payment_currency ) {
case 'USD':
$currency_symbol = '$';
break;
case 'EUR':
$currency_symbol = '€';
break;
case 'GBP':
$currency_symbol = '£';
break;
case 'AUD':
$currency_symbol = 'A$';
break;
case 'CAD':
$currency_symbol = 'C$';
break;
case 'JPY':
$currency_symbol = '¥';
break;
case 'THB':
$currency_symbol = '฿';
break;
case 'HUF':
$currency_symbol = 'Ft';
break;
case 'CHF':
$currency_symbol = 'CHF';
break;
case 'CZK':
$currency_symbol = 'Kč';
break;
case 'SEK':
$currency_symbol = 'kr';
break;
case 'DKK':
$currency_symbol = 'kr';
break;
case 'PHP':
$currency_symbol = '$';
break;
case 'MYR':
$currency_symbol = 'RM';
break;
case 'PLN':
$currency_symbol = 'zł';
break;
case 'BRL':
$currency_symbol = 'R$';
break;
case 'HKD':
$currency_symbol = 'HK$';
break;
case 'MXN':
$currency_symbol = 'Mex$';
break;
case 'TWD':
$currency_symbol = 'NT$';
break;
case 'TRY':
$currency_symbol = 'TL';
break;
}
if ( $form->payment_price_type == 'variable' ) {
//if this is multipage form, we need to get the total selected price from other pages
if ( $form->page_total > 1 ) {
$other_page_total_payment = (double) mf_get_payment_total( $dbh, $form_id, $session_id, $page_number );
$other_page_total_data_tag = 'data-basetotal="' . $other_page_total_payment . '"';
} else {
$other_page_total_data_tag = 'data-basetotal="0"';
}
} elseif ( $form->payment_price_type == 'fixed' ) {
$other_page_total_data_tag = 'data-basetotal="' . $form->payment_price_amount . '"';
}
$payment_total_markup = <<<EOT
<li class="total_payment" {$other_page_total_data_tag}>
<span>
<h3>{$currency_symbol}<var>0</var></h3>
<h5>{$webform_lang['payment_total']}</h5>
</span>
</li>
EOT;
if ( $form->payment_total_location == 'top' ) {
$payment_total_markup_top = $payment_total_markup;
} else if ( $form->payment_total_location == 'bottom' ) {
$payment_total_markup_bottom = $payment_total_markup;
} else if ( $form->payment_total_location == 'top-bottom' || $form->payment_total_location == 'all' ) {
$payment_total_markup_top = $payment_total_markup;
$payment_total_markup_bottom = $payment_total_markup;
}
}
if ( empty( $mf_settings[ 'disable_machform_link' ] ) ) {
$powered_by_markup = '';
} else {
$powered_by_markup = '';
}
//if advanced form code being used, display the form without body container
if ( $integration_method == 'phone' ) {
$form_markup = <<<EOT
<div id="main_body" class="{$container_class}">
<div class="ios">
<div class="view om_form">
<div id="form_container">
<h1><a>{$form->name}</a></h1>
<form id="form_{$form->id}" class="appnitro {$form->label_alignment}" {$form_enc_type} method="post" data-highlightcolor="{$field_highlight_color}" action="">
{$form_desc_div}
<ul {$ul_class}>
{$pagination_header}
{$payment_total_markup_top}
{$form->error_message}
{$all_element_markup}
{$custom_element}
{$payment_total_markup_bottom}
{$form_resume_markup}
{$button_markup}
<input type="hidden" name="latitude" />
<input type="hidden" name="longitude" />
</ul>
</form>
</div></div></div>
</div>
EOT;
} else {
$form_markup = <<<EOT
<div class="phone ios">
<div class="mobform" id="mobform">
<div class="view om_form">
<div id="form_container" class="{$form_container_class}">
<h1><a>{$form->name}</a></h1>
<form id="form_{$form->id}" class="appnitro {$form->label_alignment}" {$form_enc_type} method="post" data-highlightcolor="{$field_highlight_color}" action="#main_body">
{$form_desc_div}
<ul {$ul_class}>
{$pagination_header}
{$payment_total_markup_top}
{$form->error_message}
{$all_element_markup}
{$custom_element}
{$payment_total_markup_bottom}
{$form_resume_markup}
{$button_markup}
<input type="hidden" name="latitude" />
<input type="hidden" name="longitude" />
</ul>
</form>
</div></div></div>
</div>
EOT;
}
return $form_markup;
}
/**display the form within the form builder page
*
* @access public
* @param string
* @param array()
* @param int
* @return str
*/
public static function display_webform_raw_form( $image_url, $webform_lang, $form_id )
{
$pagination_header = '';
$pagination_footer = '';
$row = FormDetail::findOneRow( "form_id = '{$form_id}'", array( ) );
//var_dump($row);
//exit();
if ( count( $row ) > 0 ) {
$form = new stdClass();
$form->id = $form_id;
$form->name = $row->form_name;
$form->description = $row->form_description;
$form->label_alignment = $row->form_label_alignment;
$form->page_total = $row->form_page_total;
$form->lastpage_title = $row->form_lastpage_title;
$form->submit_primary_text = $row->form_submit_primary_text;
$form->submit_secondary_text = $row->form_submit_secondary_text;
$form->submit_primary_img = $row->form_submit_primary_img;
$form->submit_secondary_img = $row->form_submit_secondary_img;
$form->submit_use_image = (int) $row->form_submit_use_image;
$form->pagination_type = $row->form_pagination_type;
}
$matrix_elements = array( );
//get elements data
//get element options first and store it into array
$element_options = FormElementOptions::findAllRow( "form_id = '{$form_id}' and live = 1 order by element_id asc, position asc", array( ) );
if ( count( $element_options ) > 0 ) {
foreach ( $element_options as $frm_ele_opt ) {
$element_id = $frm_ele_opt->element_id;
$option_id = $frm_ele_opt->option_id;
$options_lookup[ $element_id ][ $option_id ][ 'position' ] = $frm_ele_opt->position;
$options_lookup[ $element_id ][ $option_id ][ 'option' ] = $frm_ele_opt->option;
$options_lookup[ $element_id ][ $option_id ][ 'option_is_default' ] = $frm_ele_opt->option_is_default;
}
}
//get elements data
$element = array( );
$frm_elements = FormElements::findAllRow( "form_id = '{$form_id}' and element_status='1' order by element_position asc", array( ) );
//$sth = mysql_query($query);
$j = 0;
$has_calendar = false;
$has_guidelines = false;
$page_title_array = array( );
if ( count( $frm_elements ) > 0 ) {
foreach ( $frm_elements as $element_row ) {
$element_id = $element_row->element_id;
//lookup element options first
$element_options = array( );
if ( !empty( $options_lookup[ $element_id ] ) ) {
$i = 0;
foreach ( $options_lookup[ $element_id ] as $option_id => $data ) {
$element_options[ $i ] = new stdClass();
$element_options[ $i ]->id = $option_id;
$element_options[ $i ]->option = $data[ 'option' ];
$element_options[ $i ]->is_default = $data[ 'option_is_default' ];
$element_options[ $i ]->is_db_live = 1;
$i++;
}
}
//populate elements
$element[ $j ] = new stdClass();
$element[ $j ]->title = nl2br( $element_row->element_title );
$element[ $j ]->instructions = $element_row->element_instructions;
if ( !empty( $element_row->element_instructions ) && ( $element_row->element_type != 'section' ) && ( $element_row->element_type != 'matrix' ) ) {
$has_guidelines = true;
}
$element[ $j ]->size = $element_row->element_size;
$element[ $j ]->default_value = htmlspecialchars( $element_row->element_default_value );
$element[ $j ]->is_required = $element_row->element_is_required;
$element[ $j ]->is_unique = $element_row->element_is_unique;
$element[ $j ]->is_private = $element_row->element_is_private;
$element[ $j ]->type = $element_row->element_type;
$element[ $j ]->position = $element_row->element_position;
$element[ $j ]->id = $element_row->element_id;
$element[ $j ]->is_db_live = 1;
$element[ $j ]->is_design_mode = true;
$element[ $j ]->choice_has_other = (int) $element_row->element_choice_has_other;
$element[ $j ]->choice_other_label = $element_row->element_choice_other_label;
$element[ $j ]->choice_columns = (int) $element_row->element_choice_columns;
$element[ $j ]->time_showsecond = (int) $element_row->element_time_showsecond;
$element[ $j ]->time_24hour = (int) $element_row->element_time_24hour;
$element[ $j ]->address_hideline2 = (int) $element_row->element_address_hideline2;
$element[ $j ]->address_us_only = (int) $element_row->element_address_us_only;
$element[ $j ]->date_enable_range = (int) $element_row->element_date_enable_range;
$element[ $j ]->date_range_min = $element_row->element_date_range_min;
$element[ $j ]->date_range_max = $element_row->element_date_range_max;
$element[ $j ]->date_enable_selection_limit = (int) $element_row->element_date_enable_selection_limit;
$element[ $j ]->date_selection_max = (int) $element_row->element_date_selection_max;
$element[ $j ]->date_disable_past_future = (int) $element_row->element_date_disable_past_future;
$element[ $j ]->date_past_future = $element_row->element_date_past_future;
$element[ $j ]->date_disable_weekend = (int) $element_row->element_date_disable_weekend;
$element[ $j ]->date_disable_specific = (int) $element_row->element_date_disable_specific;
$element[ $j ]->date_disabled_list = $element_row->element_date_disabled_list;
$element[ $j ]->file_enable_type_limit = (int) $element_row->element_file_enable_type_limit;
$element[ $j ]->file_block_or_allow = $element_row->element_file_block_or_allow;
$element[ $j ]->file_type_list = $element_row->element_file_type_list;
$element[ $j ]->file_as_attachment = (int) $element_row->element_file_as_attachment;
$element[ $j ]->file_enable_advance = (int) $element_row->element_file_enable_advance;
$element[ $j ]->file_auto_upload = (int) $element_row->element_file_auto_upload;
$element[ $j ]->file_enable_multi_upload = (int) $element_row->element_file_enable_multi_upload;
$element[ $j ]->file_max_selection = (int) $element_row->element_file_max_selection;
$element[ $j ]->file_enable_size_limit = (int) $element_row->element_file_enable_size_limit;
$element[ $j ]->file_size_max = (int) $element_row->element_file_size_max;
$element[ $j ]->submit_use_image = (int) $element_row->element_submit_use_image;
$element[ $j ]->submit_primary_text = $element_row->element_submit_primary_text;
$element[ $j ]->submit_secondary_text = $element_row->element_submit_secondary_text;
$element[ $j ]->submit_primary_img = $element_row->element_submit_primary_img;
$element[ $j ]->submit_secondary_img = $element_row->element_submit_secondary_img;
$element[ $j ]->page_title = $element_row->element_page_title;
$element[ $j ]->page_number = (int) $element_row->element_page_number;
$element[ $j ]->page_total = $form->page_total;
$element[ $j ]->matrix_allow_multiselect = (int) $element_row->element_matrix_allow_multiselect;
$element[ $j ]->matrix_parent_id = (int) $element_row->element_matrix_parent_id;
$element[ $j ]->range_min = $element_row->element_range_min;
$element[ $j ]->range_max = $element_row->element_range_max;
$element[ $j ]->range_limit_by = $element_row->element_range_limit_by;
$element[ $j ]->constraint = $element_row->element_constraint;
if ( !empty( $element_options ) ) {
$element[ $j ]->options = $element_options;
} else {
$element[ $j ]->options = '';
}
if ( $element_row->element_type == 'page_break' ) {
$page_title_array[ ] = $element_row->element_page_title;
}
//if the element is a matrix field and not the parent, store the data into a lookup array for later use when rendering the markup
if ( $element_row->element_type == 'matrix' && !empty( $element_row->element_matrix_parent_id ) ) {
$parent_id = $element_row->element_matrix_parent_id;
$el_position = $element_row->element_position;
$matrix_elements[ $parent_id ][ $el_position ][ 'title' ] = $element[ $j ]->title;
$matrix_elements[ $parent_id ][ $el_position ][ 'id' ] = $element[ $j ]->id;
$matrix_child_option_id = '';
foreach ( $element_options as $value ) {
$matrix_child_option_id .= $value->id . ',';
}
$matrix_child_option_id = rtrim( $matrix_child_option_id, ',' );
$matrix_elements[ $parent_id ][ $el_position ][ 'children_option_id' ] = $matrix_child_option_id;
//remove it from the main element array
$element[ $j ] = array( );
unset( $element[ $j ] );
$j--;
}
$j++;
}
}
//generate html markup for each element
$all_element_markup = '';
foreach ( $element as $element_data ) {
//if this is matrix field, build the children data from $matrix_elements array
if ( $element_data->type == 'matrix' ) {
$element_data->matrix_children = $matrix_elements[ $element_data->id ];
}
$element_prop_name = "ElementHelper::display_webform_" . $element_data->type;
//$all_element_markup .= call_user_func( $element_prop_name, $image_url, $webform_lang, $element_data, "Edit" );
}
if ( empty( $all_element_markup ) ) {
$all_element_markup = '<li id="li_dummy">&nbsp;</li>';
}
if ( !empty( $form->name ) || !empty( $form->description ) ) {
$form->description = nl2br( $form->description );
$form_desc_div = <<<EOT
<div id="form_header" class="form_description">
<h2 id="form_header_title">{$form->name}</h2>
<p id="form_header_desc">{$form->description}</p>
</div>
EOT;
} else {
$form_desc_div = <<<EOT
<div id="form_header" class="form_description">
<h2 id="form_header_title"><i>This form has no title</i></h2>
<p id="form_header_desc"></p>
</div>
EOT;
}
if ( $has_guidelines ) {
$container_class = "integrated";
} else {
$container_class = "integrated no_guidelines";
}
//if the form has multiple pages
//display the pagination header
$display_pagination = '';
if ( $form->page_total > 1 ) {
$display_pagination = "display:none;";
//build pagination header based on the selected type. possible values:
//steps - display multi steps progress
//percentage - display progress bar with percentage
//disabled - disabled
if ( $form->pagination_type == 'steps' ) {
$page_titles_markup = '';
$i = 1;
foreach ( $page_title_array as $page_title ) {
if ( $i == 1 ) {
$ap_tp_num_active = ' ap_tp_num_active';
$ap_tp_text_active = ' ap_tp_text_active';
} else {
$ap_tp_num_active = '';
$ap_tp_text_active = '';
}
$page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num' . $ap_tp_num_active . '">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text' . $ap_tp_text_active . '">' . $page_title . '</span></td><td align="center" class="ap_tp_arrow">&gt;</td>' . "\n";
$i++;
}
//add the last page title into the pagination header markup
$page_titles_markup .= '<td align="center"><span id="page_num_' . $i . '" class="ap_tp_num">' . $i . '</span><span id="page_title_' . $i . '" class="ap_tp_text">' . $form->lastpage_title . '</span></td>';
$pagination_header = <<<EOT
<li id="pagination_header" class="li_pagination" title="Click to edit">
<table class="ap_table_pagination" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
{$page_titles_markup}
</tr>
</table>
</li>
EOT;
} else if ( $form->pagination_type == 'percentage' ) {
$page_total = count( $page_title_array ) + 1;
$percent_value = round( ( 1 / $page_total ) * 100 );
$pagination_header = <<<EOT
<li id="pagination_header" class="li_pagination" title="Click to edit">
<h3 id="page_title_1">Page 1 of {$page_total} - {$page_title_array[0]}</h3>
<div class="mf_progress_container">
<div id="mf_progress_percentage" class="mf_progress_value" style="width: {$percent_value}%"><span>{$percent_value}%</span></div>
</div>
</li>
EOT;
} else {
$pagination_header = <<<EOT
<li id="pagination_header" class="li_pagination" title="Click to edit">
<h3 class="no_header">Pagination Header Disabled</h3>
</li>
EOT;
}
if ( $form->submit_use_image == 1 ) {
$btn_class = ' hide';
$image_class = '';
} else {
$btn_class = '';
$image_class = ' hide';
}
$pagination_footer = <<<EOT
<li title="Click to edit" class="page_break synched" id="li_lastpage">
<div>
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="ap_table_pagination">
<tbody><tr>
<td align="left" style="vertical-align: bottom;">
<input type="submit" class="btn_primary btn_submit{$btn_class}" name="btn_submit_lastpage" id="btn_submit_lastpage" value="{$form->submit_primary_text}" disabled="disabled">
<input type="submit" class="btn_secondary btn_submit{$btn_class}" name="btn_prev_lastpage" id="btn_prev_lastpage" value="{$form->submit_secondary_text}" disabled="disabled">
<input type="image" src="{$form->submit_primary_img}" class="img_primary img_submit{$image_class}" alt="Submit" name="img_submit_lastpage" id="img_submit_lastpage" value="Submit" disabled="disabled">
<input type="image" src="{$form->submit_secondary_img}" class="img_secondary img_submit{$image_class}" alt="Previous" name="img_prev_lastpage" id="img_prev_lastpage" value="Previous" disabled="disabled">
</td>
<td width="75px" align="center" style="vertical-align: top;">
<span class="ap_tp_text" name="pagetotal_lastpage" id="pagetotal_lastpage"> {$form->page_total} / {$form->page_total}</span>
</td>
</tr>
</tbody></table>
</div>
</li>
EOT;
}
$no_field_display = '';
if ( count( $element ) <= 0 ) {
$no_field_display .= '<div id="no_fields_notice" class="notice">';
$no_field_display .= '<h2> <b> No Fields!</b> You should add a field.</h2>';
$no_field_display .= '<p><span style="color: #529214; font-weight: bold;">Click the buttons</span> on the left sidebar or <span style="color: #529214; font-weight: bold;">Drag it here</span> to add new field.</p>';
$no_field_display .= '</div>';
}
$form_markup = <<<EOT
<div id="form_container">
<form id="form_builder_preview" class="appnitro {$form->label_alignment}" method="post" action="#main_body">
{$form_desc_div}
{$no_field_display}
<ul id="form_builder_sortable" title="Click field to edit. Drag to reorder.">
{$pagination_header}
{$all_element_markup}
{$pagination_footer}
</ul>
</form>
</div>
<div title="Click to edit" class="page_break synched" id="li_default_lastpage" style="background: none repeat scroll 0 0 #F0F0F0;border-bottom: 1px solid #FFFFFF;clear: both;margin: 0;padding: 6px 1% 9px;position: relative;{$display_pagination}" >
<span class="om_handle"></span>
<div id="form_element_lastpage">
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="ap_table_pagination">
<tbody><tr>
<td align="left" style="vertical-align: bottom">
<input type="submit" class="btn_primary btn_submit" name="btn_submit_default_lastpage" id="btn_submit_0" value="Submit" disabled="disabled">
<input type="image" class="img_primary img_submit" name="img_submit_default_lastpage" id="img_submit_0" value="Continue" alt="Continue" src="/formbuilder//images/empty.gif" disabled="disabled">
</td>
</tr>
</tbody></table>
</div>
</div>
EOT;
return $form_markup;
}
}
?>[code]
Hi!
Please don’t expect ANYONE to read this unformatted MASS of code.
Learn to use code blocks to format your code:
// use the below this line without the // at beginning.
// [code]your well formattet php code [ /code]
// Then your code looks like this:
public function example(){
$test "Just a Test to show code formatting in the yii forum!";
return $test;
}
Regards
Thanks for your suggestion…