Send image from page to enquiry form

Hi - have had success with sending text info from a page to an enquiry form - using the following code:

Page:

<a class="submit" href="<?= page('enquiry')->url() . '?painting=' . $page->reference()->html() . $page->headline()->html() ?>">ENQUIRE </a>

Form:

<input name="subject" id="subject" type="text" value="Enquiry regarding the painting: <?php echo $_GET['painting'] ?>" placeholder="Subject">

This results in:

Enquiry regarding the painting: 016-Untitled

I need help with also sending, if possible, the image from the page, so that it shows up as a small thumbnail on the enquiry form alongside the text information. (Actually anywhere on the form page would be fine).

Hopeful result:

Enquiry regarding the painting: DHN-016-Untitled (actual small image)

This is the code on the page that I am using to display the image:

<?php if ($cover = $page->images()->findBy("template", "cover")): ?><?php endif ?>

<img src="<?= $cover->url() ?>

Would really appreciate any help with how to do this!
Thanks

If you have the page, you can fetch the image from that page. Does the information you pass along in your link contain the title or id of the page? Anything that is unique, so you can do a $pages->findBy('reference'), for example?

Yes, the information I am passing along to the form contains the image reference number and its title (headline). The image on the main page is displayed by:
<img src="<?= $cover->url() ?>
So I am trying to find a way to pass along that, and display it on the form page together with the other information. I tried the following:

<a class="submit" href="<?= page('enquiry')->url() . '?painting=' . $page->reference()->html() . $page->headline()->html() .$cover->url() ?>">ENQUIRE </a>

but that just achieves:

Enquiry regarding the painting: DHN-002-Untitledhttp://localhost/media/pages/artworks1/56756756375637356731627/1854008064-1588947839/6798768658536863782714.jpg

So I am obviously missing how to display the image not the url string!

No, we don’t need that, we need to get the page, you can pass the page id as a second query param, then we can get the page with

<?php
if ($referencePage = page(get('pagereference')) {
  if ($image = $referencePage->cover()) {
    echo $image;
  }
}
?>

I am so sorry - you are losing me a little!

This code is placed in enquiry.php page?
Can you show the entire thing - not sure where to put my <?php and my end ifs!

Thank you so much

Let’s say you send the link like this:

<a class="submit" href="<?= page('enquiry')->url() . '?painting=' . $page->reference()->html() . $page->headline()->html() . '&referencepage=' . $page->id() ?>">ENQUIRE </a>

Then on the page with the form, you put the code I mentioned above, where you want to show the image.

OK, so the code above on the main page is working as I can see in the url that it is passing all the info - but the enquiry page won’t load due to an error.

I am placing

<?php
if ($referencePage = page(get('pagereference')) {
  if ($image = $referencePage->cover()) {
    echo $image;
  }
}
?>

in its own column on the enquiry page for now just to test.

Ah, I forgot a closing parens:

<?php
if ($referencePage = page(get('pagereference'))) {
  if ($image = $referencePage->cover()) {
    echo $image;
  }
}
?>

OK, so no error now - but sadly no image.
You have the patience of a saint - bear with me!

What does you link url look like now?

localhost/enquiry?painting=DHN-777-untitled&referencepage=artworks1/title1

So get('referencepage') should then give you artworks1/title1.

And page(get('referencepage')) the page with the image

Try

dump(page(get('referencepage')));

in your enquiry template and see what it gives you

Kirby\Cms\Page Object
(
    [children] => Kirby\Cms\Pages Object
        (
        )

    [content] => Kirby\Cms\Content Object
        (
            [title] => Title1
            [artist] => David Smith
            [fp_status] => true
            [reference] => DHN-777-
            [type] => Painting
            [medium] => Oil on canvas
            [headline] => Untitled
            [year] => 2020
            [category] => home
            [shortnarrative] => 
            [narrative] => 
            [narrative_documents] => 
            [purchasedate] => 
            [soldto] => 
            [financialnotes] => 
            [documents] => 
            [location] => 
            [first_owner] => 
            [subtext1] => 
        )

    [files] => Kirby\Cms\Files Object
        (
            [0] => artworks1/title1/painting1.jpg
        )

    [id] => artworks1/title1
    [mediaUrl] => http://localhost/media/pages/artworks1/title1
    [mediaRoot] => D:\www/media/pages/artworks1/title1
    [num] => 8
    [parent] => artworks1
    [slug] => title1
    [template] => Kirby\Cms\Template Object
        (
            [name:protected] => artwork1
            [type:protected] => html
            [defaultType:protected] => html
        )

    [translations] => Kirby\Cms\Collection Object
        (
        )

    [uid] => title1
    [uri] => artworks1/title1
    [url] => http://localhost/artworks1/title1
    [siblings] => Kirby\Cms\Pages Object
        (
            [0] => artworks1/56756756375637356731627
            [1] => artworks1/464336245624513467245671
            [2] => artworks1/34534245675476562462
            [3] => artworks1/2387463874328762384623
            [4] => artworks1/342342342342343276454
            [5] => artworks1/2342321124213453
            [6] => artworks1/4234234327777213213
            [7] => artworks1/title1
        )

)

Perfect, that’s exactly what we need, isn’t it?

So all that is missing is the file, I thought that was the one stored in a cover field but if there’s only one image, we can get it like this:

<?php
if ($referencePage = page(get('referencepage'))) {
  if ($image = $referencePage->image()) {
    echo $image;
  }
}
?>

And the answer is yes we can!
Perfect!! Works like a charm.
Thank you so much

Need Help. Our is art gallery show casing paintings
Need enquiry form where user can forward image too
Plz check page like

where there are vlots of paintings . Now if any user want to enquire about any painting he can press enquiry button and that particlualar image also gets forwarded so that we get to know for which painting customer is interested