• I am trying to use the “placeholder” (aka “watermark”) option with dynamictext. If I use the following tag in my form:

    [dynamictext* your-registration-key placeholder “CF7_GET key=’regid'”]

    I get a placeholder but the text is “CF7_GET key=’regid'”. The value, if any, is not retrieved. However, that is not the functionality I want. I would like to be able to specify a value for the placeholder and still have the dynamic value retrieved is there is one. I know from the CF7 documentation that tags are in the format:

    [type name options values]

    For text object, the doc shows that only one value is possible. But for select objects, multiple values are allowed. I have looked through the plugin code and I am not yet up-to-speed on CF7 functions or WordPress coding. I have been trying to see if a tag such as this would be valid:

    [dynamictext* your-registration-key placeholder “Registration ID” “CF7_GET key=’regid'”]

    In such a scenario, the placeholder would use the first value and the tag variable would use the second value. My tests so far have failed but I am wondering if I just have the order of things wrong.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • If you are using CF7_GET key why are you wanting a placeholder? The field will be prefilled with your text anyway, so a placeholder wouldn’t be seen.

    EDIT: Re-Read your post – missed the second bit! Have you tried

    [dynamictext* your-registration-key "CF7_GET key='regid'" placeholder "Registration ID"]

    Thread Starter n2jtx

    (@n2jtx)

    There are two ways a user can bring up the form. Either entering the URL manually, in which case “regid” is undefined and they need to type it in, or through a link in my firms application in which case the variable is supplied by the software to the URL. I am looking for the placeholder when “regid” is blank. It appears I might be able to hack this as $tag->values is an array and I would need logic to determine if there is more than one value and if “placeholder” is present.

    Thread Starter n2jtx

    (@n2jtx)

    It seems a hack for this was quite simple. With this change I can now specify [dynamictext variable-name placeholder “Default Value” “Placeholder Value”]. If “Placeholder Value” is not specified, then “Default Value” is used for the placeholder text instead:

    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    
    //PATCH: Allow user specific placeholder text as the last value.
    // First value will be used if it is blank.
    $value = (string) reset( $tag->values );
    $value2 = (string) next( $tag->values );
    
    if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
    	$atts['placeholder'] = ( '' !== $value2 ? $value2 : $value );
    	$value = '';
    	$value2 = '';
    }
    
    $value = (string) reset( $tag->values );
    //END PATCH
    
    $value = $tag->get_default_option( $value );

    Where do you put this code?

    Thread Starter n2jtx

    (@n2jtx)

    In version 2.0.1, go into “edit” for this plugin and search for the first line in the code snippet above (the one with ‘aria-invalid’). Underneath it you will see the “$value =” assignment. Highlight that line and paste in the code from above between the “//PATCH” and “//END PATCH” comments to replace it. Save it and you should be good to go.

    thanks for the patch, works fine on my end.
    @admin author: please re-implement the placeholder functionality into the plugin..

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Correct use of "placeholder" option?’ is closed to new replies.