• Resolved n2jtx

    (@n2jtx)


    I had a need for a text box that could be edited if it’s default value was blank but be read-only if it contained a value (supplied through a parameter in the URL). The “uneditable” tag did not work because the field was always read-only. I made the following two line change to the “uneditable” tag code and create a new “editifblank” tag as follows:

    if(in_array('uneditable', $options)){
    	$readonly = 'readonly="readonly"';
    } elseif(in_array('editifblank', $options) && ( '' !== $value )) {
    	$readonly = 'readonly="readonly"';
    }

    https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author sevenspark

    (@sevenspark)

    Yup, that’d require some customizations as you mentioned, there isn’t any conditional-readonly logic built into the plugin.

    Thread Starter n2jtx

    (@n2jtx)

    Due to the 2.0 plugin changes, I had to modify the code as follows:

    if ( $tag->has_option( 'readonly' ) ) {
    		$atts['readonly'] = 'readonly';
    	} elseif ( $tag->has_option( 'editifblank' ) && ( '' !== $value ) ) {
    		$atts['readonly'] = 'readonly';
    	}
    Thread Starter n2jtx

    (@n2jtx)

    Actually my previous code did not work completely because $value was not yet defined. A simple change as follows got it working again:

    $atts['value'] = $value;
    
    //PATCH: Create the "editifblank" option.  Must be checked AFTER
    // $value is defined.
    if ( $tag->has_option( 'editifblank' ) && ( '' !== $value ) ) {
    	$atts['readonly'] = 'readonly';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Created a Conditional Edit Box’ is closed to new replies.