Infusionsoft_WebFormService::getJavaScript PHP Метод

getJavaScript() публичный статический Метод

Instead of having to use the HTML code, you can get the JavaScript snippet. The web form displayed by the snippet will be updated automatically when it is updated in Infusionsoft.
Автор: Jacob Allred ([email protected])
public static getJavaScript ( integer $webFormId, Infusionsoft_App $app = null ) : string
$webFormId integer The ID from Infusionsoft_WebFormService::getMap.
$app Infusionsoft_App
Результат string JavaScript snippet for the web form.
    public static function getJavaScript($webFormId, Infusionsoft_App $app = null)
    {
        $app = parent::getObjectOrDefaultAppIfNull($app);
        /*
         * The API doesn't provide a method of getting the JavaScript snippet.
         * Instead, we are going to get the HTML, find the form GUID, and create
         * the JavaScript snippet on our own.
         */
        // Get the HTML
        $html = Infusionsoft_WebFormService::getHTML($webFormId, $app);
        // Create our search string
        $search = $app->getHostname() . '/app/form/process/';
        // Find the start and stop position of the form GUID
        $start = strpos($html, $search) + strlen($search);
        $stop = strpos(substr($html, $start), '"');
        // Pull out the GUID
        $guid = substr($html, $start, $stop);
        // Put together the JavaScript snippet
        $snippet = '<script type="text/javascript" src="https://';
        $snippet .= $app->getHostname();
        $snippet .= '/app/form/iframe/' . $guid . '"></script>';
        return $snippet;
    }