Using multiselect to populate another field on seperate page

Hi,

I have created a section in the cms titled “Venues”. Inside venues i’ve created a few children pages with some basic blueprints like title, email, phone etc.

In another section on my site I have a “live listings” section with children pages. What I would like is that when I create a new “live listing” or choose a current one. The venue and number field should be a multiselect from the “venues” section above.

So to make things clear, I want the venue / contact number and lat long to be a multiselect field that only allows me to choose from the children pages in “venues”.

So If i have a venue called “Bobs Comedy Store” inside Venues. I then want to create a live listing called “Sally Biggins @ Bobs Comedy Store” inside live-listings. When it comes to the venue and number fields. I want it to be a multiselect that once I select Bob’s Comedy Store the venue and number should come from the “Bobs Comedy Store” Entry.

Hopefully I’ve explained this well enough.

UPDATE:

I managed to use the following blueprint to pull the venue title into the live-listings venue field.

venue:
    label: Venue
    type: select
    options: query
    query:
      page: venues
      fetch: children
      value: '{{uri}}'
      text: '{{title}}'

But the problem is that when I try to use this same format under the “contact number” field it only shows me the phone number in the dropdown, i’ve no way to distinguish which venue it belongs too

But why do you need the number in the live listing? You could just get the number of the venue in your template instead of repeating the information in the live listing.

Edit: but you can add additional information like this:

venue:
    label: Venue
    type: select
    options: query
    query:
      page: venue
      fetch: children
      value: '{{uri}}'
      text: '{{title}}: {{number}}' 

Yes you are correct. Ive just realised that now.

Im going to remove the other fields except venue.

So now the fields look like this:

But to output this in the php, the field needs to be dynamic, in the picture ive selected vicar street but it could be any of 10 venues. So how do i make sure that whatever venue is clicked the php will be outputted correctly?

Like this:

<?php
$venue = $page->venue();
$number = page('venues')->children()->find($venue)->number();

I can’t seem to be able to output using the above.

My current page is live. The children of live are all the live listing entries.

So I presumed it would need to be altered a little like this

<?php
 $venue = $page->children()->venue(); // to get the actual listings venue (which is a select field)
 $number = page('venues')->children()->find($venue)->number();
?>

or something along those lines? I think the select field is causing problems because I cant even access the venue() if I run this

<?php
<?php $venue = $page->children()->venue(); ?>
<h1><?php echo $venue ?></h1>
?>

Well, you have to loop through the children:

<?php
foreach($page->children() as $child) {
  $venue = $child->venue();
  $venuePage = page('venues')->children()->find($venue);
  $number = $venuePage->number();
}
?>

Could you please use three backticks on a separate line before and after a block of code to make your code more readable? Thanks!

Sorry about the formatting!

Thanks for your help but It’s still not working. But I think I know why.

When we are declaring

$venue = $child->venue();
echo $venue
 // When I echo $venue the result "venues/vicar-street' appears
 // So I think because we are trying to pass this back into the children string it can't find it.
<?php $venuePage = page('venues')->children()->find($venue); ?>

//Because if I loop to find out the venues children pages titles I get "Vicar Street" without any of the url bits.
<?php foreach($page->children() as $child) : ?>
  <?php foreach(page('venues')->children() as $venuePage) : ?>
  	<?php echo $venuePage->title(); ?>
  <?php endforeach ?>
<?php endforeach ?>

Do you think I’m onto something? Ive spent 4-5 hours doing this now and its driving me insane lol.
Thanks for all your help so far.

Oh, I see, the field contains the URI, not the UID, I missed that. So we have to change it a little bit:

<?php
foreach($page->children() as $child) {
  $venue = $child->venue();
  $venuePage = page($venue);
  $number = $venuePage->number();
}
?>

I played around with that code a little and I have both variables matching now.

<?php
foreach($page->children() as $child) {
  $venue = $child->venue();
  echo "live listing child venue is $venue";
  echo "------------";
  $venuePage = page($venue);
  echo "Venue Listing child venue is $venuePage";
  echo "-----------";
}
?>

So now they both match, Do i integrate it back into the code you provided earlier?

You probably missed my last code snippet? Anyway, they are both the same now and you can take it from there… :slight_smile:

Yes thank for you all your help.

One thing thats extremely frustrating me is the fact Im not able to access the contact blueprint inside any of the pages.

<?php foreach($page->children() as $child): ?>
	<?php $venue = $child->venue(); ?>
	<?php $venuePage = page($venue); ?>
	<?php foreach($venuePage->contact() as $number): ?>
		<?php echo $number ?>
	<?php endforeach ?>
<?php endforeach ?>

Do you know why it wont let me access the number field via echo or looping a foreach?

What sort of a field is the contact field?

A plain text field

  contact:
    label: Contact number
    type: text

You can’t simply loop through a text field. You can use $venuePage->contact()->split("\n") though.

Something like this?

<?php foreach($page->children() as $child): ?>
	<?php $venue = $child->venue(); ?>
	<?php $venuePage = page($venue); ?>
	<?php foreach($venuePage->contact()->split('\n') as $number): ?>
		<?php echo $number ?>
	<?php endforeach ?>
<?php endforeach ?>

Still gives me an error?

It probably makes more sense to separate the contact data into separate fields. Makes it much more reliable to access in case the contact information is not always built in the same way.

Edit: How does the content of the contact field look in the text file?

The thing is there is only 1 number for each venue. The listings with that chosen venue all have that same number then inside them (front end).

note: just make sure to scroll to the bottom, contact is the last field

Venue.txt

Title: Vicar Street

----

Text: 

----

Address: 123 dame street

----

Ticketlink: http://www.link.com

----

Latlong: 55,55

----

Contact: 666666

Ok, then the contact field just contains a number and you don’t need to split anything or loop through it but simply echo it:

echo $venuePage->contact();
<?php foreach($page->children() as $child): ?>
	<?php $venue = $child->venue(); ?>
	<?php $venuePage = page($venue); ?>
	<?php echo $venuePage->contact(); ?>
<?php endforeach ?>

This should just output the number but it still errors and I have no idea why

What sort of error do you get?