Jump to content

Tutorial for dropdown in front end: PageField or Select Options Fieldtype?


Lmwt
 Share

Recommended Posts

Hi there,

I am new to PW but already very convinced. I need to build a dropdown button to browse in a collection of authors by country and language. The dropdown should be editable in the BACK and displayed on the same as the authors collection. I tried my luck with "PageField Creator" but I don't know how to display the dropdown, I simply used: 

"$content .=$page->Land;" (the name of the select field)

but nothing is displayed...

I see there is a 2nd module out there to achieve this : "Select Options Fieldtype". I am not sure what is the difference, anyone has a tip?

And a clear tutorial with the necessary steps to build this? I am a bit confused which should be the parent template or page, if it should have a file or not...

Thanks a lot in advance!

Link to comment
Share on other sites

I asume you are talking about the page reference field. With "Select Options Fieldtype" you define options in field settings, while for page reference field, you use pages as options (any pages), you can select pages by template, parent page, or a custom selector etc... For the dropdown, you have to write your own markup, processwire doesn't do any automatic front-end work for you.

Link to comment
Share on other sites

Hi dear helpers,

after some time I managed all the front end but... have this last problem:

I want that on "submit" the page of the selected option to be opened. I could do this easily with javascript but I CAN'T figure out how to insert a <script> tag :( why is that not working in this html markup...?

so I came up with this code where I want the selected value to be set as title of the page linked (see "action" in the form tag):

<form id="search_lang" action='<?php echo $pages->get('template=publisher-language, title=$selected')->url;?>' method='get'>
				
				<label for='search_lang'>Language</label>
				<select id='search_lang' name='lang'>
						<option value='' selected></option>
				<?php
								foreach ($pages->get("languages-index")->children() as $lang) {
								$selected = $lang->id == $input->whitelist->lang ? " selected='selected' " : '';
								echo "<option value='$lang->url'>{$lang->title}</option>";
						}

				 ?>
				 </select>
				 <p><input type='submit' id='search_submit_lang' name='submit' value='Submit' /></p>

				</form>

Thanks for helping newbies!

Link to comment
Share on other sites

  • 3 months later...
On 10/24/2019 at 10:32 PM, Lmwt said:

Hi dear helpers,

after some time I managed all the front end but... have this last problem:

I want that on "submit" the page of the selected option to be opened. I could do this easily with javascript but I CAN'T figure out how to insert a <script> tag ? why is that not working in this html markup...?

so I came up with this code where I, want the selected value to be set as title of the page linked (see "action" in the form tag):

Spoiler

 

Thanks for helping newbies!

Hi buddy, did you get any way out to this? Falling under same issue.

 

Regards,

V. Smih  https://mycfavisit.me/survey/  https://tellgamestop.vip/tellgamestop-survey-enter/

Link to comment
Share on other sites

36 minutes ago, vijih said:

Hi buddy, did you get any way out to this? Falling under same issue.

 After reading and re-reading the posts here a few times, I must admit that I'm lost. What is the problem you're running into? ?

On 10/24/2019 at 8:02 PM, Lmwt said:

I could do this easily with javascript but I CAN'T figure out how to insert a <script> tag ? why is that not working in this html markup...?

I realize that this is an old topic, but... in what HTML markup exactly, and how (and where) are you trying to add that script tag? ?

If you're editing a template file, you can just add in the script tag — just like any code. Or was your issue that the script itself is not working? If it's the latter case, please share the markup and the script so we can better figure out what's going on.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...