• Resolved mattsson

    (@mattsson)


    Hello,

    I’ve created a Constant Contact form to save visitor name, email and phone to a particular Constant Contact list. Upon successful form submittal, the visitor is taken directly to a link. My question is, how can I add a form field of type “hidden”?

    My purpose is, I’ll have several related forms, one for each variation of the premium link. There is a unique link for each of a dozen cities, that is. I’d like to save in the hidden form variable, for which city the visitor requested the link. Then when my client looks up this particular contact, she can see what area the contact is interested in.

    I’d expect this feature to be a choice in the menu where I select the field type, but it’s not there. Maybe somewhere else? A checkbox for the field perhaps?

    Thanks in advance,
    Carol Mattsson
    Web developer

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Constant Contact

    (@constantcontact)

    The closest we’d have for this feature, in regards to UI, would be custom fields, but those don’t currently have any setup for pre-selected values and the user would have to fill them in somehow.

    Beyond that, and we can’t guarantee that the use-case is even fully viable, the solution would have to be code-based. We’re not sure at the moment exactly what parts you’d need to custom interact with, and we’d have to get back to you on any leads/ideas there. The biggest question would ultimately be where those values could be stored at for your entries, and how to get them set.

    Thread Starter mattsson

    (@mattsson)

    Hi Constant Contact,

    Thanks for thinking about the hidden variable feature. My use case is, I want to create several forms, one for each of a list of cities. I’m using each CC form to harvest contact info in exchange for providing a link to info on each specific city. I’m using ONE CC folder to store all such harvested contacts. I want to know which city the contact is interested in. I could set up a CC folder for each city, I suppose. But I would only need ONE CC folder if I could pass the city name in a hidden field instead.

    The UI design that would work for me is:

    1) Some sort of checkbox to say yes add a hidden variable.

    2) If Checked, choose which custom field I’d like to store the hidden variable value in. Choose from a list please, since custom field names get mixed up over time as the various forms utilize them.

    3) A text field for the value I’d like to pass in the hidden variable.

    Sincerely,
    Carol Mattsson
    Web developer for long time user of Constant Contact

    Plugin Author Constant Contact

    (@constantcontact)

    Understood on a very valid use case and situation.

    It’s largely coming down to how does one accomplish this with what is currently available in the plugin as well as how we could potentially help make the task easier from our end.

    At least with how I know the code is now, my mind is ending up wandering towards a javascript solution of some sort. As is, it’d be the only way to really dynamically inject some new fields that one could also assign over as field values to a different field that would be included as part of the submitted data. It would definitely have to be a custom field and also one that is below a max length allowed. We had support issues in the past where custom fields that were too long were rejected by the API without any real indication.

    That limit could largely be stayed within, say if you used some sort of abbreviation system, say “NYC” for New York, or “CHI” for Chicago, etc.

    Just a note regarding custom field names, the Constant Contact admin area doesn’t utilize names at all, and at least with how our plugin is now, it’s just first come, first populated. We have a WordPress filter that can be used to prefix the custom field value with the custom field label, but that does end up using up available characters from the max length. As a quick example, it’d still show up as “Custom field 1” but the value would be something like “City: CHI” vs just “CHI”

    Thread Starter mattsson

    (@mattsson)

    Hi Constant Contact,

    Thanks for thinking about my request. It sounds like for now, the answer about hidden variable is a “no.”

    I thought of another possible solution to my problem though: I think I will need a different form for each of the 16 cities, because the protected link is different for each city. So if the MAILBACK subject line somehow indicated which city, that would let admin know which city the visitor was interested in.

    (You can see from my other support query, I’ve yet to receive a mailback from the form, so I don’t know what comprises the subject line. If it includes the form name, that would be helpful.)

    Cheers,
    Carol

    Plugin Author Constant Contact

    (@constantcontact)

    It’s not so much a “no” or “hard no” or however you may visualize it, it’s more a “what could be done to help facilitate this type of usecase, while not making changes specifically for just this usecase”. Abstract things out and have a good place to store the information.

    Regarding your idea of including data in the subject line, we do have something readily in place there to help, at least for majority of things. Word of warning, it is code-based so hopefully it’s not intimidating.

    /**
     * Filters the email subject to be sent to an admin.
     *
     * @since 1.3.0
     *
     * @param string $value Constructed email subject.
     * @param string $value Constant Contact Form ID.
     */
    apply_filters( 'constant_contact_email_subject', __( 'Constant Contact Forms Notification', 'constant-contact-forms' ), $submission_details['form_id'] )
    

    If you’re familiar with WordPress filters and hooks at all, this should be pretty straightforward.

    Basically, the default subject line is “Constant Contact Forms Notification”. With this filter, you could change it to whatever you wanted. As part of the filter, we provide the form ID that was submitted to, so you could conditionally act based on the form used.

    As an example, if it was form ID 42, you could have the subject line be “Douglas Adams sends his fish”, otherwise, have it return the default above.

    Regarding your usecase above, you could do something like this:

    <?php
    
    function mattsson_custom_email_subject( $default, $form_id ) {
    
    	if ( 42 === $form_id ) {
    		return 'Constant Contact Forms Notification in Chicago';
    	}
    
    	if ( 46 === $form_id ) {
    		return 'Constant Contact Forms Notification in New York City';
    	}
    
    	if ( 58 === $form_id ) {
    		return 'Constant Contact Forms Notification in San Francisco';
    	}
    
    	// Just return original if we have no found ID.
    	return $default;
    }
    add_filter( 'constant_contact_email_subject', 'mattsson_custom_email_subject', 10, 2 );
    

    You would need to match up the IDs to which city should be listed.

    Not foolproof solutions because forms can change and whatnot, but it’d work technically.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add a hidden variable?’ is closed to new replies.