Turquoisekay
Turquoisekay

Reputation: 11

Pre-filling user information from wordpress to an embedded Jotform

These two links would have provided some information but not enough https://www.jotform.com/answers/393927-grab-wordpress-username-and-populate-it-to-the-form https://www.jotform.com/answers/357275-is-it-possible-to-automatically-grab-wordpress-user-details-and-add-them-to-form

I'm trying to prepopulate two jotform fields using user information from wordpress, However, only one is being filled.

Example of code

src="https://form.jotform.com/XXXXXXXXXXX?name[first]=<?php global $current_user; get_currentuserinfo(); echo $current_user->first_name;?>"

I'm assuming it's because of name[first]=

However, how do I get it to fill two fields, the first and last name Where do I put the "&"

image example of prefilling two fields

Upvotes: 0

Views: 143

Answers (1)

amarinediary
amarinediary

Reputation: 5449

It's difficult to understand what you're trying to do. Plugins are not core so i'm flying blind here, tho from an abstract point of view:

get_currentuserinfo() was deprecated back in 4.5.

You should use wp_get_current_user().

To make it more pleasing and less clunky we can set an array of parameters, join those and merge them with our url.

<?php

$user = wp_get_current_user();

$url = 'https://form.jotform.com/XXXXXXXXXXX?';

$parameters = array(
    'name[first]' => $user->first_name,
    'name[last]' => $user->last_name,
    //...
);

$buffer = array();

foreach ( $parameters as $key => $value ) {

    array_push( $buffer, $key . '=' . $value );

};

$url .= join( '&', $buffer );

echo $url;

Upvotes: 1

Related Questions