Title: Adding a form ID with a variable
Last modified: November 18, 2021

---

# Adding a form ID with a variable

 *  Resolved [unsavouryindividual](https://wordpress.org/support/users/unsavouryindividual/)
 * (@unsavouryindividual)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/adding-a-form-id-with-a-variable/)
 * Hi,
    I’m a little lacking in my PHP and the suggested snippet for adding forms
   to templates is unfamiliar to me. How do I do something like this: `$form_widget
   = new \MailPoet\Form\Widget(); echo $form_widget->widget(array('form' => $emailid,'
   form_type' => 'php'))`
 * $emailid is where there would normally be a number. I’m drawing the variable 
   from a custom field. The variable prints “3” in my HTML when I test it. Is this
   a problem of how the string is formatted or how I’m inserting it into your snippet?
   Is there an alternative way I can build the form?
 * Thanks
    -  This topic was modified 4 years, 6 months ago by [unsavouryindividual](https://wordpress.org/support/users/unsavouryindividual/).

Viewing 1 replies (of 1 total)

 *  Plugin Support [Kel C. a11n](https://wordpress.org/support/users/kellymetal/)
 * (@kellymetal)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/adding-a-form-id-with-a-variable/#post-15090984)
 * Hi there [@unsavouryindividual](https://wordpress.org/support/users/unsavouryindividual/),
 * Just to confirm, you are getting that PHP from the Form Editor under the **Form
   Placement > Shortcode and Other > Use PHP** section, correct?
 * That spot where you replaced the number with `$emailid` would generally be the
   ID of the form that you want to add — it would grab the form with the given ID,
   and then output the form wherever you add it in your theme template.
 * So if you wanted that to be variable, you would need to make sure you have Forms
   created for each of the values of your custom field. Then when your custom field
   == 1, it would output form with ID == 1.
 * Apparently wherever you have pasted the snippet now, that custom field has a 
   value of “3”… and so if you have a form with ID 3 then it would be output there
   if you paste that whole snippet into your template file.

Viewing 1 replies (of 1 total)

The topic ‘Adding a form ID with a variable’ is closed to new replies.

 * ![](https://ps.w.org/mailpoet/assets/icon-256x256.png?rev=3284564)
 * [MailPoet - Newsletters, Email Marketing, and Automation](https://wordpress.org/plugins/mailpoet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailpoet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailpoet/)
 * [Active Topics](https://wordpress.org/support/plugin/mailpoet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailpoet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailpoet/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Kel C. a11n](https://wordpress.org/support/users/kellymetal/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/adding-a-form-id-with-a-variable/#post-15090984)
 * Status: resolved