Example #1
0
function ninja_forms_import_list_options()
{
    // Bail if we aren't in the admin
    if (!is_admin()) {
        return false;
    }
    check_ajax_referer('nf_ajax', 'nf_ajax_nonce');
    $options = $_REQUEST['options'];
    $field_id = absint($_REQUEST['field_id']);
    $options = str_replace('\\,', '-comma-replace-placeholder-', $options);
    $options = ninja_forms_csv_explode($options);
    if (is_array($options)) {
        $tmp_array = array();
        $x = 0;
        foreach ($options as $option) {
            $label = stripslashes($option[0]);
            $value = stripslashes($option[1]);
            $calc = stripslashes($option[2]);
            $label = str_replace("''", "", $label);
            $label = str_replace("-comma-replace-placeholder-", ",", $label);
            $value = str_replace("''", "", $value);
            $value = str_replace("-comma-replace-placeholder-", ",", $value);
            $calc = str_replace("''", "", $calc);
            $calc = str_replace("-comma-replace-placeholder-", ",", $calc);
            $tmp_array[$x]['label'] = $label;
            $tmp_array[$x]['value'] = $value;
            $tmp_array[$x]['calc'] = $calc;
            $x++;
        }
        $x = 0;
        foreach ($tmp_array as $option) {
            $hidden = 0;
            ninja_forms_field_list_option_output($field_id, $x, $option, $hidden);
            $x++;
        }
    }
    die;
}
Example #2
0
function ninja_forms_field_list_edit($field_id, $data)
{
    global $wpdb;
    $list_type = isset($data['list_type']) ? $data['list_type'] : '';
    $hidden = isset($data['list_show_value']) ? $data['list_show_value'] : 0;
    $multi_size = isset($data['multi_size']) ? $data['multi_size'] : 5;
    $default_options = array(array('label' => 'Option 1', 'value' => '', 'calc' => '', 'selected' => 0), array('label' => 'Option 2', 'value' => '', 'calc' => '', 'selected' => 0), array('label' => 'Option 3', 'value' => '', 'calc' => '', 'selected' => 0));
    $list_options = isset($data['list']['options']) ? $data['list']['options'] : $default_options;
    $list_type_options = array(array('name' => __('Dropdown', 'ninja-forms'), 'value' => 'dropdown'), array('name' => __('Radio', 'ninja-forms'), 'value' => 'radio'), array('name' => __('Checkboxes', 'ninja-forms'), 'value' => 'checkbox'), array('name' => __('Multi-Select', 'ninja-forms'), 'value' => 'multi'));
    ninja_forms_edit_field_el_output($field_id, 'select', __('List Type', 'ninja-forms'), 'list_type', $list_type, 'wide', $list_type_options, 'widefat');
    ?>
	
	<p id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_multi_size_p" class="description description-wide" style="<?php 
    if ($list_type != 'multi') {
        echo 'display:none;';
    }
    ?>
">
		<?php 
    _e('Multi-Select Box Size', 'ninja-forms');
    ?>
: <input type="text" id="" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[multi_size]" value="<?php 
    echo $multi_size;
    ?>
">
	</p>
	<span id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_span" class="ninja-forms-list-span">
		<!-- <p class="description description-wide"> -->
			<a href="#" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_add_option" class="ninja-forms-field-add-list-option button-secondary"><?php 
    _e('Add New', 'ninja-forms');
    ?>
</a>
			<a href="#TB_inline?width=640&height=530&inlineId=ninja_forms_field_<?php 
    echo $field_id;
    ?>
_import_options_div" class="thickbox button-secondary" title="<?php 
    _e('Import List Items', 'ninja-forms');
    ?>
" id=""><?php 
    _e('Import List Items', 'ninja-forms');
    ?>
</a>
		<!-- </p> -->

		<p class="description description-wide">
			<input type="hidden" id="" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list_show_value]" value="0">
			<label for="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_show_value"><input type="checkbox" value="1" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_show_value" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list_show_value]" class="ninja-forms-field-list-show-value" <?php 
    if (isset($data['list_show_value']) and $data['list_show_value'] == 1) {
        echo "checked='checked'";
    }
    ?>
>
			<?php 
    _e('Show list item values', 'ninja-forms');
    ?>
 </label>
		</p>
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_options" class="ninja-forms-field-list-options description description-wide">
			<input type="hidden" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list][options]" value="">
			<?php 
    if (isset($list_options) and is_array($list_options) and $list_options != '') {
        $x = 0;
        foreach ($list_options as $option) {
            ninja_forms_field_list_option_output($field_id, $x, $option, $hidden);
            $x++;
        }
    }
    ?>

		</div>
	</span>
	<?php 
    add_thickbox();
    ?>
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_import_options_div" style="display:none;">
			<textarea id="test" class="list-import-textarea"></textarea>
			<input type="button" class="save-list-import button-secondary" value="<?php 
    _e('Import', 'ninja-forms');
    ?>
" rel="<?php 
    echo $field_id;
    ?>
">
			<input type="button" class="cancel-list-import button-secondary" value="<?php 
    _e('Cancel', 'ninja-forms');
    ?>
">
			<p><?php 
    _e('To use this feature, you can paste your CSV into the textarea above.', 'ninja-forms');
    ?>
</p>
			<p><?php 
    _e('The format should look like the following:', 'ninja-forms');
    ?>
</p>
<pre>
<?php 
    $example1 = _x('Label,Value,Calc', 'Example for list importing. Leave puncation in place.', 'ninja-forms');
    echo $example1;
    echo '<br />';
    echo $example1;
    echo '<br />';
    echo $example1;
    ?>
</pre>

			<p><?php 
    _e("If you want to send an empty value or calc, you should use '' for those.", 'ninja-forms');
    ?>
</p>
<pre>
<?php 
    $example2 = __('Label', 'ninja-forms') . ",'',''";
    echo $example2;
    echo '<br />';
    echo $example2;
    echo '<br />';
    echo $example2;
    ?>
</pre>


		</div>
	<?php 
}
Example #3
0
function ninja_forms_field_list_edit($field_id, $data)
{
    global $wpdb;
    if (isset($data['list_type'])) {
        $list_type = $data['list_type'];
    } else {
        $list_type = '';
    }
    if (isset($data['list_show_value'])) {
        $hidden = $data['list_show_value'];
    } else {
        $hidden = 0;
    }
    if (isset($data['multi_size'])) {
        $multi_size = $data['multi_size'];
    } else {
        $multi_size = 5;
    }
    ?>

	<p id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_multi_size_p" class="description description-wide" style="<?php 
    if ($list_type != 'multi') {
        echo 'display:none;';
    }
    ?>
">
		<?php 
    _e('Multi-Select Box Size', 'ninja-forms');
    ?>
: <input type="text" id="" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[multi_size]" value="<?php 
    echo $multi_size;
    ?>
">
	</p>
	<p class="description description-wide">
		<a href="#" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_collapse_options" name="" class="ninja-forms-field-collapse-options"><?php 
    _e('Expand / Collapse Options', 'ninja-forms');
    ?>
</a>
	</p>
	<span id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_span" class="ninja-forms-list-span" style="display: none;">
		<p class="description description-wide">
			<?php 
    _e('Options', 'ninja-forms');
    ?>
: <a href="#" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_add_option" class="ninja-forms-field-add-list-option button-secondary"><?php 
    _e('Add New', 'ninja-forms');
    ?>
</a>
			<a href="#TB_inline?width=640&height=530&inlineId=ninja_forms_field_<?php 
    echo $field_id;
    ?>
_import_options_div" class="thickbox button-secondary" title="<?php 
    _e('Import List Items', 'ninja-forms');
    ?>
" id=""><?php 
    _e('Import Options', 'ninja-forms');
    ?>
</a>
		</p>

		<p class="description description-wide">
			<input type="hidden" id="" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list_show_value]" value="0">
			<label for="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_show_value"><input type="checkbox" value="1" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_show_value" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list_show_value]" class="ninja-forms-field-list-show-value" <?php 
    if (isset($data['list_show_value']) and $data['list_show_value'] == 1) {
        echo "checked='checked'";
    }
    ?>
>
			<?php 
    _e('Show option values', 'ninja-forms');
    ?>
 </label>
		</p>
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_list_options" class="ninja-forms-field-list-options description description-wide">
			<input type="hidden" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[list][options]" value="">
			<?php 
    if (isset($data['list']['options']) and is_array($data['list']['options']) and $data['list']['options'] != '') {
        $x = 0;
        foreach ($data['list']['options'] as $option) {
            ninja_forms_field_list_option_output($field_id, $x, $option, $hidden);
            $x++;
        }
    }
    ?>

		</div>
	</span>
	<?php 
    add_thickbox();
    ?>
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_import_options_div" style="display:none;">
			<textarea id="test" class="list-import-textarea"></textarea>
			<input type="button" class="save-list-import button-secondary" value="<?php 
    _e('Import', 'ninja-forms');
    ?>
" rel="<?php 
    echo $field_id;
    ?>
">
			<input type="button" class="cancel-list-import button-secondary" value="<?php 
    _e('Cancel', 'ninja-forms');
    ?>
">
			<p><?php 
    _e('To use this feature, you can paste your CSV into the textarea above.', 'ninja-forms');
    ?>
</p>
			<p><?php 
    _e('The format should look like the following:', 'ninja-forms');
    ?>
</p>
<pre>
<?php 
    $example1 = _x('Label,Value,Calc', 'Example for list importing. Leave puncation in place.', 'ninja-forms');
    echo $example1;
    echo '<br />';
    echo $example1;
    echo '<br />';
    echo $example1;
    ?>
</pre>

			<p><?php 
    _e("If you want to send an empty value or calc, you should use '' for those.", 'ninja-forms');
    ?>
</p>
<pre>
<?php 
    $example2 = __('Label', 'ninja-forms') . ",'',''";
    echo $example2;
    echo '<br />';
    echo $example2;
    echo '<br />';
    echo $example2;
    ?>
</pre>


		</div>
	<?php 
}
Example #4
0
function ninja_forms_import_list_options()
{
    $options = $_REQUEST['options'];
    $field_id = absint($_REQUEST['field_id']);
    $options = str_replace('\\,', '-comma-replace-placeholder-', $options);
    $options = csv_explode($options);
    if (is_array($options)) {
        $tmp_array = array();
        $x = 0;
        foreach ($options as $option) {
            $label = stripslashes($option[0]);
            $value = stripslashes($option[1]);
            $calc = stripslashes($option[2]);
            $label = str_replace("''", "", $label);
            $label = str_replace("-comma-replace-placeholder-", ",", $label);
            $value = str_replace("''", "", $value);
            $value = str_replace("-comma-replace-placeholder-", ",", $value);
            $calc = str_replace("''", "", $calc);
            $calc = str_replace("-comma-replace-placeholder-", ",", $calc);
            $tmp_array[$x]['label'] = $label;
            $tmp_array[$x]['value'] = $value;
            $tmp_array[$x]['calc'] = $calc;
            $x++;
        }
        $x = 0;
        foreach ($tmp_array as $option) {
            $hidden = 0;
            ninja_forms_field_list_option_output($field_id, $x, $option, $hidden);
            $x++;
        }
    }
    die;
}