Viewing 10 replies - 1 through 10 (of 10 total)
  • Hello! Thank you for using Ninja Forms. You can use a hook to modify the default value of any field in which you can use PHP.

    Thread Starter adminbart

    (@adminbart)

    Thank you for your reply!

    Perhaps I don’t undestrand your answer, but I don’t need it to be in a field, it just needs to be shown somewhere in the form and in the emails (admin and user).

    But perhaps I need to modify a field as you say, can you help me on how to do that?
    I’m a designer, not a developer, so this may sound a stupid question ??

    Kind regards, Bart

    You can use a field, but set it to be readonly so it cannot be modified by the user and this will show up on the front end and in the emails.

    You can use this hook to modify the default value of the field.

    Do you want to use the image URL or the product page’s URL?

    Thread Starter adminbart

    (@adminbart)

    Thanks for the fast answer. I will check your link over an hour from now.

    I want to use the image url, because there are more than one item on a page.

    You are welcome. Ah I understand. All right. If you need any further help, just let me know! ??

    Thread Starter adminbart

    (@adminbart)

    Hello Respectyoda,

    I can’t seem to get it right ??
    But as I mentioned: I’m not a developer.

    How can I set a field to readonly?
    How can I retrieve the fields ID?

    Is it the main functions.php-file of the theme where I add this?

    <?php
     // instead of the URL I want an image
    $url = '<img src="'. $_GET["foto"] . '">';
    
    function my_filter_function( $data, $field_id ){
      if( $field_id == 3 ){$data['default_value'] = $url;}
      return $data;
    }
    add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );

    Should the code look like this?

    I hope I’m not asking too much of your time ??

    Kind regards,
    Bart

    Yes, it is the functions.php file the code must be in.

    If you want the textbox to be readonly then go to the particular form in the backend -> Restriction Settings -> Disable input (make sure this box is checked).

    As for the field’s ID, once again, go to the particular form in the backend and open the field to show information about the field. There you should find the field ID.

    As for the code, you really don’t need the img tags, just the URL.

    function my_filter_function( $data, $field_id ){
      if ( $field_id == 3 ){
        $data['default_value'] = $_GET["foto"];
      }
      return $data;
    }
    add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );
    Thread Starter adminbart

    (@adminbart)

    Great! You’re a genius! Thanks!!!

    But because I’m using a texfield I see a field with the URL in it, but not an image. Perhaps there’s a way to show the image?

    You are welcome!

    So you want to show the image of the product in the email?

    Thread Starter adminbart

    (@adminbart)

    Goodmorning respectyoda, thats wright, I would like to show the image.
    If it possible ??

    Have a nice day!
    Bart

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Get image form variable’ is closed to new replies.