728x90

What I'm trying to achieve is to create one module that contains multiple functions in it.

 

 

The problem I have is that the firstParam is an object type and the secondParam is a URL string, but when I have that it always complains that the type is wrong.

How can I declare multiple module.exports in this case?

 

 

stackoverflow.com/questions/16631064/declare-multiple-module-exports-in-node-js

728x90

Many users find it helpful to export their Gravity Forms entries as a PDF for better ability to print them as well as attach them within an email. In this article, we will show you how to use a 3rd party plugin to easily export your Gravity Forms entries as a PDF.

Downloading the Gravity PDF Add-On

While Gravity Forms does not have the ability to natively export entries as a PDF, another developer has developed a solution that works quite well.

  1. First, log into your WordPress admin dashboard.
  2. Next, hover over Plugins and click on Add New.
  3. On the top right of the page, search for Gravity PDF.
  4. Upon searching, your first result should be Gravity PDF from Blue Liquid Designs. Simply click the Install Now button.
  5. WordPress will now handle the download and installation of the Gravity PDF plugin for you. Be sure to activate the plugin once complete.

Exporting Entries as PDF

  1. First, click on Forms on the left side menu.
  2. Next, hover over the form that you want to view entries for. Upon doing so, you will see additional options appear. Click on Entries.
  3. You should now be looking at a list of your entries. Hover over your desired entry, and click on View PDF.
  4. You will now be presented with a PDF of your Gravity Forms entry.

Questions & Support

The Gravity PDF Add-On is created by a third-party developer and as such is not supported by our team, please contact the plugin developer if you have any questions about its features or require support for any issues.

728x90

이 글은 ‘JavaScript — The Conditional (Ternary) Operator Explained by Brandon Morelli’ 를 번역한 글입니다.

기본부터 시작하다 — if 문

if 문처럼 조건부(conditional)를 사용한다면, 특정 조건이 충족되면 특정 블록의 코드가 실행되어야 되는 것을 허락합니다.

다음 예시를 봅시다:

우리는 driver, name, age 라는 프로퍼티(property)를 가진 person 객체(object)를 예시로 봅시다.

let person = {
name: 'tony',
age: 20,
driver: null
};

우리는 person 나이가 16보다 크거나 같은지 실험을 해보고 싶습니다. 만약 해당 실험이 참이라면, 사람은 운전 가능한 나이고 driver 은 ‘yes’ 라고 할 것입니다. 만약 해당 정보가 거짓이면 driver 은 ‘No’를 반환할 것입니다.

해당 실험은 if 문으로 작성할 수 있습니다:

if (person.age >= 16) {
person.driver = 'Yes';
} else {
person.driver = 'No';
}

그러나 우리가 위에 완성된 if 문을 한 줄의 코드로 작성할 수 있습니다. 자, 여기있습니다:

person.driver = person.age >=16 ? 'Yes' : 'No';

이 짧은 코드는 우리에게 동일한 person.driver = ‘Yes’; 의 결과를 산출합니다.

The Conditional (Ternary) Operator (조건부 삼항 연산자)

우선, 우리는 정형적인 if 문법을 보겠습니다:

if ( condition ) {
value if true;
} else {
value if false;
}

자, 이제 ternary operator(조건부 삼항 연산자) 로 바꿔볼까요?:

condition ? value if true : value if false

당신이 알아야할 것은 다음과 같습니다:

  1. condition(조건) 이 당신이 실험하고 있는 것이다. 당신의 condition(조건)의 결과는 진실 또는 거짓입니다. 아니면 적어도 boolean 값은 일치해야한다.
  2. A ? 는 우리의 conditional(조건부)과 true value 값을 구분합니다. ?  : 사이에 있는 모든 condition(조건)은 true(참)이면 실행된다.
  3. 마지막으로 : 은 조건의 상태가 거짓으로 평가되면 : 이후에 나오는 코드는 실행된다.

예시 — Driver(운전자)의 나이

다시 처음 예시를 살펴보자:

let person = {
name: 'tony',
age: 20,
driver: null
};person.driver = person.age >=16 ? 'Yes' : 'No';

가장 중요한 것은 operations(연산자) 순서이다. 코드를 실행하는 순서를 시각화하는데 도움이 되는 parenthesis(괄호)를 추가해보자.

person.driver = ((person.age >=16) ? 'Yes' : 'No';)

시각화하면, 우리의 conditional(조건부) 가 person.age > = 16 값이 참인지 거짓인지 처음으로 확인한다.

20 16보다 크기 때문에 true(참)으로 평가한다. 지금 우리는 여기까지 왔다:

person.driver = (true ? 'Yes' : 'No';)

우리의 conditional(조건부)의 condition(조건) 이 true 이므로, ?  : 사이에 있는 값이 리턴된다. 해당 예시같은 경우에는 ‘Yes’ 결과 값이 나온다.

리턴 값이 있기에 마지막으로 해야할 일은 변수와 동일하게 설정하는 것이다.

person.driver = 'Yes';

축하합니다! 이제 좀더 복잡한 예시를 살펴봅시다.

예시 — 학생할인

해당 예시에서 우리가 영화관을 위해 코딩을 한다고 합시다. 영화관은 두 가지의 표 가격을 제시합니다: 일반인은 $12 그리고 학생은 $8 으로 가격을 제시합니다.

구매하는 사람이 학생인지 아닌지의 여부를 추적할 변수를 생성합시다:

let isStudent = true;

해당 변수를 통해 우리는 ternary operator( 삼항 연산자) 를 사용하여 가격을 변동할 수 있습니다.

let price = isStudent ? 8 : 12
console.log(price);
// 8

isStudent boolean 이 true(참) 이므로, 8 값이 다중 삼항(ternary)으로부터 price 변수로 리턴됩니다.

예시 — Nested Ternary

하지만, 만약 영화관에서 학생과 노인에게 할인을 한다면 어떻게 할까요?

우리는 다양한 조건을 실험하기 위해서 nest(네스트) 된 ternary operator( 삼항 연산자) 사용할 수 있습니다.

해당 시나리오를 확인하면 티켓은 : 일반인은 $12, 학생은 $8 그리고 노인은 $6 입니다.

노인인구를 추정하는 코드는 다음과 같습니다:

let isStudent = false;
let isSenior = true;
let price = isStudent ? 8 : isSenior ? 6 : 10console.log(price);
// 6

해당 예시는 복잡합니다. 그러니 이를 짧게 나누어봅시다.

  1. 우선, 우리는 티켓 구매자가 학생인지 알아봐야합니다. isStudent 가 false(거짓) 이므로, 첫 번째 : 이후의 코드만 실행합니다. : 이후에는 새로운 조건부가 있습니다.
  2. 두번째 조건부는 isSenior 를 확인해봅니다. — 이가 true(참) 이기 때문에 ? 이후 : 이전의 코드만 실행합니다.
  3. price 는 6의 값이 할당된다.

예시- Multiple operations (다수의 조건)

Multiple operations(다수의 조건) 를 ternary 안에 실행할 수 있습니다. 이를 위해, 우리는 쉼표로 조건을 나누어야 합니다. 또한, 추가적으로 괄호를 사용하여 코드를 그룹화 할 수 있습니다.

let isStudent = true;
let price = 12;
isStudent ? (
price = 8,
alert('Please check for student ID')
) : (
alert('Enjoy the movie')
);

위의 예시에서 우리의 영화 price (가격) 는 이미 $12 로 지정되어 있습니다. 만약 isStudent  true(참) 이면 , 우리는 price 를 $8로 조정하고 판매자에게 학생증 확인하는 alert (경고)를 보냅니다. 만약 isStudent  false(거짓) 이면, 위의 코드는 생략하고, 영화를 즐기라는 경고가 나옵니다.

 

medium.com/@saerombang11/%EB%B2%88%EC%97%AD-%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%A1%B0%EA%B1%B4%EB%B6%80-%EC%82%BC%ED%95%AD-%EC%97%B0%EC%82%B0%EC%9E%90-conditional-operator-%EC%84%A4%EB%AA%85%ED%95%98%EB%8B%A4-ac8afdb294ab

728x90

Viewed 197 times

 

-1

I want to use a multi-step form where the user enters their name in step one, then on step two the form will say "Hello, [name]" with the rest of the content and steps to follow.

Any ideas?

EDIT: I want to use data entered in step one on step 2. Reading GF documentation I think something like {[Field Name]:[field_id]} should work, but it does not. Digging further I found that this would only work once a form has been submitted already. So my question is, is there a way that will enable me to use the merge tags within the current form from data being submitted in a previous step?

pluginsplugin-gravity-forms

share  improve this question  follow 

edited Mar 30 '19 at 15:17

 

asked Mar 29 '19 at 20:17

 

Rowbee

32 bronze badges

  •  

    Welcome to WordPress development! Unfortunately it's unclear what you are asking as you didn't tell us what exactly you've tried so far and where you are stuck right now. Please update your question accordingly as otherwise it's just too broad. – leymannx Mar 30 '19 at 8:59

  •  

    That is fair. I am trying to use merge tags in a multi-step form. I want to use data entered in step one on step 2. Reading GF documentation I think something like {[Field Name]:[field_id]} should work, but it does not. Digging further I found that this would only work once a form has been submitted already. So my question is, is there a way that will enable me to use the merge tags within the current form from data being submitted in a previous step? – Rowbee Mar 30 '19 at 15:15 

 

 

0

This is possible with Live Merge Tags, a feature of Gravity Forms Populate Anything.

If you're looking to get your hands dirty with some code, Gravity Forms has an example of how this might work with a snippet on their docs for the gform_pre_render filter:

https://docs.gravityforms.com/gform_pre_render/#3-populate-field-with-values-from-earlier-page

 

gform_pre_render - Gravity Forms Documentation

The gform_pre_render filter is executed before the form is displayed and can be used to manipulate the Form Object prior to rendering the form.

docs.gravityforms.com

 

 

3. Populate Field With Values From Earlier Page

This example is for a two-page form. The data submitted from the first page is displayed on the second page as a preview. The second page has only one field, an html field that will be populated with the data from the first page.

add_filter( 'gform_pre_render_81', 'populate_html' );

function populate_html( $form ) {

    //this is a 2-page form with the data from page one being displayed in an html field on page 2

    $current_page = GFFormDisplay::get_current_page( $form['id'] );

    $html_content = "The information you have submitted is as follows:<br/><ul>";

    if ( $current_page == 2 ) {

        foreach ( $form['fields'] as &$field ) {

            //gather form data to save into html field (id 6 on my form), exclude page break

            if ( $field->id != 6 && $field->type != 'page' ) {

                //see if this is a complex field (will have inputs)

                if ( is_array( $field->inputs ) ) {

                    //this is a complex fieldset (name, adress, etc.) - get individual field info

                    //get field's label and put individual input information in a comma-delimited list

                    $html_content .= '<li>' .$field->label . ' - ';

                    $num_in_array = count( $field->inputs );

                    $counter = 0;

                    foreach ( $field->inputs as $input ) {

                        $counter++;

                        //get name of individual field, replace period with underscore when pulling from post

                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );

                        $value = rgpost( $input_name );

                        $html_content .= $input['label'] . ': ' . $value;

                        if ( $counter < $num_in_array ) {

                            $html_content .= ', ';

                        }

                    }

                    $html_content .= "</li>";

                } else {

                    //this can be changed to be a switch statement if you need to handle each field type differently

                    //get the filename of file uploaded or post image uploaded

                    if ( $field->type == 'fileupload' || $field->type == 'post_image' ) {

                        $input_name = 'input_' . $field->id;

                        //before final submission, the image is stored in a temporary directory

                        //if displaying image in the html, point the img tag to the temporary location

                        $temp_filename = RGFormsModel::get_temp_filename( $form['id'], $input_name );

                        $uploaded_name = $temp_filename['uploaded_filename'];

                        $temp_location = RGFormsModel::get_upload_url( $form['id'] ) . '/tmp/' . $temp_filename['temp_filename'];

                        if ( !empty( $uploaded_name ) ) {

                            $html_content .= '<li>' . $field->label . ': ' . $uploaded_name . "<img src='" . $temp_location . "' height='200' width='200'></img></li>";

                        }

                    } else {

                        //get the label and then get the posted data for the field (this works for simple fields only - not the field groups like name and address)

                        $field_data = rgpost('input_' . $field->id );

                        if ( is_array( $field_data ) ){

                            //if data is an array, get individual input info

                            $html_content .= '<li>' . $field->label . ': ';

                            $num_in_array = count( $field_data );

                            $counter = 0;

                            foreach ( $field_data as $data ) {

                                $counter++;

                                $html_content .= print_r( $data, true );

                                if ( $counter < $num_in_array ) {

                                    $html_content .= ', ';

                                }

                            }

                            $html_content .= '</li>';

                        }

                        else {

                            $html_content .= '<li>' . $field->label . ': ' . $field_data . '</li>';

                        }

                    }

                }

            }

        }

        $html_content .= '</ul>';

        //loop back through form fields to get html field (id 6 on my form) that we are populating with the data gathered above

        foreach( $form['fields'] as &$field ) {

            //get html field

            if ( $field->id == 6 ) {

                //set the field content to the html

                $field->content = $html_content;

            }

        }

    }

    //return altered form so changes are displayed

    return $form;

}

 

+ Recent posts