Add custom text to contact form via shortcode WordPress 7


Cray

I'm using Contact Fom 7 and need to add custom text somewhere on the form.

I am using PHP to get custom text from a subfield of an advanced custom field. I know, there is an extra plugin called "Contact Form 7 Dynamic Text Extension" ( https://de.wordpress.org/plugins/contact-form-7-dynamic-text-extension/ ). But since the text is in a subfield, I can't use it.

So, what I need is to hide the text in the input field or form generated email.

I think it's a custom parameter in the CF7 shortcode itself. like this:

[contact-form-7 id="1" title="Title" customtext="Text"]

Is that possible?

Or is it possible to use a header and add it to an input field or form's email?

Wasim Sheikh

You have a field called "customtext" as the target email address:

[text* customtext]

To get the default value from the shortcode attribute, add the default:shortcode_attr option to the form-tag:

[text* customtext default:shortcode_attr]

Then, add the attribute with the same name as the field ("customtext" in this case) to the contact form's shortcode:

[contact-form-7 id="123" title="Contact Form" customtext="[email protected]"]

You need to register this property beforehand.

Add the following code snippet to your theme's functions.php file:

add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );

function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $my_attr = 'customtext;

if ( isset( $atts[$my_attr] ) ) {
    $out[$my_attr] = $atts[$my_attr];
}

return $out;
}

Reference link : https://contactform7.com/getting-default-values-from-shortcode-attributes/

Related


Add custom text to contact form via shortcode WordPress 7

Cray I'm using Contact Fom 7 and need to add custom text somewhere on the form. I am using PHP to get custom text from a subfield of an advanced custom field. I know, there is an extra plugin called "Contact Form 7 Dynamic Text Extension" ( https://de.wordpres

HTML output for Wordpress Contact Form 7 custom shortcode

Sebastian I want to customize the HTML output of the Wordpress Contact Form 7 (WPCF7) shortcode itself (ie the [file]shortcode ) . I don't want to modify the surrounding HTML . So far I have modified the HTML output by changing the content of the file /contact

HTML output for Wordpress Contact Form 7 custom shortcode

Sebastian I want to customize the HTML output of the Wordpress Contact Form 7 (WPCF7) shortcode itself (ie the [file]shortcode ) . I don't want to modify the surrounding HTML . So far I have modified the HTML output by changing the content of the file /contact

How can I add my own shortcode in Contact Form 7?

Nurik For example I have the function function simple_title( ){ return get_the_title(); } add_shortcode( 'page-title', 'simple_title' ); But I can't add this [page-title] in body message contact form 7? jogesh_pi For this to work, you have to modify Contact F

How can I add my own shortcode in Contact Form 7?

Nurik For example I have the function function simple_title( ){ return get_the_title(); } add_shortcode( 'page-title', 'simple_title' ); But I can't add this [page-title] in body message contact form 7? jogesh_pi For this to work, you have to modify Contact F

WordPress - Contact Form 7 - Validate Custom Fields

maaak I need to validate custom select field in contact form 7. The custom code [mycode] in Contact Form 7 is generating the following HTML: <select name="shuttleprice-1" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required shuttleprice" aria-req

WordPress - Contact Form 7 - Validate Custom Fields

maaak I need to validate custom select field in contact form 7. The custom code [mycode] in Contact Form 7 is generating the following HTML: <select name="shuttleprice-1" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required shuttleprice" aria-req

WordPress - Contact Form 7 - Validate Custom Fields

maaak I need to validate custom select field in contact form 7. The custom code [mycode] in Contact Form 7 is generating the following HTML: <select name="shuttleprice-1" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required shuttleprice" aria-req

Add border and background to Contact 7 form Wordpress

cool I am trying to add border and background color in Contact Form 7. I used "Inspect Element" to see what class/id to target, but I didn't find a class/id that would target the entire form as a whole. Everything I've tried (such as .wpcf7-form and .wpcf7) is

Add border and background to Contact 7 form Wordpress

cool I am trying to add border and background color in Contact Form 7. I used "Inspect Element" to see which class/id to target, but I didn't find a class/id that would target the entire form as a whole. Everything I've tried (like .wpcf7-form and .wpcf7) is f

Add target="_parent" to <form> tag on WordPress contact form 7?

Steve Walker I am creating a form that will be embedded in another site. I would like to be redirected to the "thank you" page on the parent page on submit. Is there a way to add the target="_parent" attribute to the form tag in my contact form 7? thanks, stev

Get custom field value in contact form 7 in Wordpress

adash On my website I have a page showing job openings. Each job opening is completed as a position. So when you click on a job opening, it will go to the details page and show the full details. All job detail pages have a unique job ID and are being entered t

Get custom field value in contact form 7 in Wordpress

adash On my website I have a page showing job openings. Each job opening is completed as a position. So when you click on a job opening, it will go to the details page and show the full details. All job detail pages have a unique job ID and are being entered t

Add Google Conversion Code to WordPress Contact Form 7

codeFLOWee I found a tutorial for adding Google conversion code to the WordPress Contact Form 7 plugin, which can be found here . Currently, I have added <script type="text/javascript"> $(".wpcf7-form").submit(function(){ var google_conversion_id =

Dynamically add WordPress post title in Contact Form 7

Istiyak Mahmoud I am working on a WordPress site and there is a working section there. Where users can apply for jobs, that's why I created a Contact Formreceive application with the applicant's name, email, address, and resume. Now, when applicants click appl

WordPress Custom Contact Form Issues

Scorpion I created a custom "contact us" form for my wordpress site that should work on every static page of my site. So I put the html in header.php below the body tag, attached the style.css file that activates the theme, and added the css code in the form b

Contact Form 7 plugin, wordpress

the The form works fine and all fields are displayed. Although each dropdown select menu will display an additional dropdown menu below it. The other options below don't have borders or CSS styles, and I'm not sure why this is due to my inexperience with CSS.