• Resolved unsavouryindividual

    (@unsavouryindividual)


    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

Viewing 1 replies (of 1 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there @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.