Forum Replies Created

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • in reply to: add custom class or attribute to frontend form #5996
    Marc
    Member

    @friendlyfire3,

    It is possible, and depends on what you want to do.

    To add classes to individual fields:

    
       piklist('field', array(
        'type' => 'text'
        ,'scope' => your_scope
        ,'field' => 'name'
        ,'label' => __('Name', 'namespace')
        ,'required' => true
        ,'template' => 'theme'
        ,'attributes' => array(
          'class' => 'something', // this class is applied directly to the field input
          'wrapper_class' => 'form-group', // this class is applied to the wrapper
          'data-whatever' => 'a data', // this data attribute is applied to the input
        )
      ));
    
    

    If you want to add classes to all your fields, you can use a hook.
    Here’s a function I used to add bootstrap classes to a contact form:

    
    /* function add_form_classes
    
    Adds Bootstrap classes to piklist forms
    */
    function add_form_classes( $field ) {
    	switch ( $field['type'] ) {
    		case 'text':
    		case 'textarea':
    		case 'password':
    		// you might want to add more choices here
    			$field['attributes']['class'][] = 'form-control';
    			break;
    		case 'submit':
    			$field['attributes']['class'][] = 'btn';
    			break;
    	}
    
    	return $field;
    
    }
    add_filter( 'piklist_pre_render_field', 'add_form_classes' );
    

    In that case I only checked the type of field to add the classes, but you have access to all of the field’s options, so you can also do something different depending on the scope and so on.

    There’s a more extensive use of this hook in piklist-demos.php, line 302 – function piklist_demo_pre_render_field()

    Hope this helps!

    in reply to: Limiting file fields to a single image? #5948
    Marc
    Member

    The part that works for me is in the media Library Lightbox.
    You can only select one picture, even while holding shift.

    But if you click on Select again, this will add an other picture.
    So as I said before it only works half.

    in reply to: Limiting file fields to a single image? #5945
    Marc
    Member

    Yes it works using the Media Uploader
    I pasted this code in Piklist demos, and it works. Not sure why it doesn’t for you!

    
    piklist('field', array(
      'type' => 'file'
      ,'field' => 'header_photo_id'
      ,'scope' => 'user_meta'
      ,'label' => __('Header Photo','piklist')
      ,'description' => __('Choose a photo to replace the default on your profile page.','piklist')
      ,'validate' => array(
        array(
          'type' => 'limit'
          ,'options' => array(
            'min' => 1
            ,'max' => 1
          )
          ,'message' => 'Sorry, you can only select one image for this.'
        )
      )
      ,'options' => array(
        'modal_title' => __('Choose Header Photo','piklist')
        ,'button' => __('Select','piklist')
        ,'multiple' => false // must be boolean, not string
      )
    ));
    
    in reply to: Limiting file fields to a single image? #5943
    Marc
    Member

    Ok, I think I know.
    This works for me with piklist 0.9.9.7:
    Add
    ,’multiple’ => false

    to the options array:

    
    ,'options' => array(
      'modal_title' => __('Choose Header Photo','piklist')
      ,'button' => __('Select','piklist')
      ,'multiple' => false
    )
    

    Or At list it limits to one the selection in the Media window.
    If you click ‘Add’ again, it adds an other picture.
    So half a solution!

    in reply to: Limiting file fields to a single image? #5941
    Marc
    Member

    @Adrian
    Try adding this to your field:

    
    ,'attributes' => array(
          'data-multiple' => false
    )
    
    in reply to: Plugin Translation #5621
    Marc
    Member

    @Steve

    What I’m also suggesting through that is to add flexibility to users who would like their own translated strings.
    Because Piklist will have such a broad range of usage, there will probably be people who would rather use their own translated string instead of the default one.
    But it’s only a suggestion.

    I’ll look into this link, I’ll gladly help.

    in reply to: Plugin Translation #5610
    Marc
    Member

    Well I should say it allow it when you insert it just before the line
    load_plugin_textdomain('piklist', false, 'piklist/languages/');

    in reply to: Plugin Translation #5609
    Marc
    Member

    I’m using v0.9.9.7. I also checked from the trunk download to be sure and it seems to be the latest version?

    The string is translatable, but the file piklist-fr_FR.mo doesn’t seem to have a full translation (also it weights 5kb against 32kb for the Spanish version).
    Which is ok of course, I know you guys are working hard to get v1 soon and probably don’t speak all the languages on Earth :).

    What I tried is to put my own piklist-fr_FR.mo in wp_content/languages/ to avoid overriding it in wp_content/plugins/piklist/languages/, which would be bad practice I think :).

    Which is what the load_textdomain( 'piklist', WP_LANG_DIR . '/piklist/piklist' . '-' . get_locale() . '.mo' ); allows.

    in reply to: Plugin Translation #5593
    Marc
    Member

    @Steve – Hi there,

    I’m making a website in French, and using a frontend contact form with Piklist.
    I saw that the validation strings weren’t translated.

    Long story short, I made a french .po file, but in order for it to work I have to override the plugin’s piklist-fr_FR.mo file. Which we will agree, is not a good way to do as on next update my changes will be lost.
    So I came across a solution to allow the language files to be overriden if you put the mo file in wp_content/languages/piklist/:

    In the file class-piklist.php

     
        // loads the user's file
        $domain = 'piklist';
        $mo_file = WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . get_locale() . '.mo';
        load_textdomain( $domain, $mo_file );
        // loads the plugin's file
        load_plugin_textdomain('piklist', false, 'piklist/languages/');
    

    I thought it could be quite useful to some users.

    Thanks again for an amazing plugin + support!

    Marc.

    in reply to: Add_More issues #5341
    Marc
    Member

    I just had an idea and tried this instead, in a custom field:

    
    <a href="#" class="button">My button</a>
    <input 
      type="hidden"
      id="<?php echo piklist_form::get_field_id($arguments); ?>" 
      name="<?php echo piklist_form::get_field_name($arguments); ?>"
      value="<?php echo esc_attr($value); ?>" 
      <?php echo piklist_form::attributes_to_string($attributes); ?>
    />
    

    A button (not as a input) and a hidden input.
    The repeater works well, and it will probably allow me to do what I need to.

    in reply to: Add_More issues #5340
    Marc
    Member

    I wanted to create a custom field with some custom JS and functions, but when I tried something simple the add_more didn’t work. So I tried with the already existing fields.

    in reply to: Add_More issues #5339
    Marc
    Member

    Here it is:

    
    piklist('field', array(
    	'type' => 'group'
    	,'field' => 'section_builder'
    	,'template' => 'field'
    	,'fields' => array(
    		array(
    			'type' => 'group'
    			, 'field' => 'section_group'
    			, 'add_more' => true
    			, 'fields' => array(
    				array(
    					'type' => 'button'
    					,'field' => 'section_add_btn'
    					,'label' => 'A label'
    					,'attributes' => array(
    						'value' => 'The Button'
    						,'class' => 'button'
    					)
    				)
    				, array(
    					'type' => 'hidden'
    					,'field' => 'section'
    				)
    			)
    		)
    	)
    ));
    
    

    I tried with the button field on its own and add more and the same happens:

    piklist( 'field', array(
    		'type' => 'button'
    		,'field' => 'section_add_btn'
    		,'label' => 'Add a section'
    		,'add_more' => true
    		,'attributes' => array(
    			'class' => 'button'
    		)
    	)
    );
    

    The JS code in piklist/parts/js/piklist.js clearly removes the value parameter.
    This file piklist/parts/js/piklist.js downloaded from the trunk says it’s been modified in october. So maybe something is not up to date?

    in reply to: Add_More issues #5319
    Marc
    Member

    I wasn’t, I was using 0.9.9.6
    But after updating to 0.9.9.7, I encounter the same problem.
    The value is correct if I save, but JS that duplicates the fields removes all values except for :checkbox and :radio, and not :button
    piklst.js – line 1327

                        if (!$(this).is(':checkbox, :radio'))
                        {
                          $(this).removeAttr('value');
                        }
    

    So if I add :button after :radio, it works perfectly.

    Attachments:
    You must be logged in to view attached files.
    in reply to: Add_More issues #5316
    Marc
    Member

    Hi there,
    Sorry to revive an old subject.
    I’m trying to add a button field with add_more, but on pressing the + button, the javascript removes the value of the new button, hence removing its text.
    I believe it would make sence to change in piklist.js line 1327

    
                        if (!$(this).is(':checkbox, :radio'))
                        {
                          $(this).removeAttr('value');
                        }
    

    to

    
                        if (!$(this).is(':checkbox, :radio, :button'))
                        {
                          $(this).removeAttr('value');
                        }
    

    maybe even adding a class like .no-reset-on-repeat if (!$(this).is(':checkbox, :radio, :button, .no-reset-on-repeat')) would allow flexibility for fields that could be repeated with the same value.

    Marc.

    in reply to: Build a Contact Form with Piklist 0.9.9.6? #5284
    Marc
    Member

    Thanks @Steve.
    I thought there was a more clever way to do 🙂
    So I suppose $_POST['_contact'] should be $_POST[ piklist::$prefix . 'contact' ] right?

Viewing 15 posts - 1 through 15 (of 20 total)