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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By spercy16
      I was previously using individual fields to capture and output multiple cards onto my web page but after recently learning about repeaters would prefer to use this field type, as it will be a lot more user friendly for end users to create new cards. I tried to modify my code to grab the fields from the new Repeater field(s) but am getting this error message on the page:
      Here is the code I'm currently trying to use for the cards:
      <?php // https://processwire.com/api/arrays/ // check if the array of images has items foreach($page->tall_card as $card) { $count = 0; $count++; $options = array( 'quality' => 70 ); $image = $card->image; $img = $card->image->size(550, 400, $options); $cardHeading = $card->title; $cardBody = $card->plain_paragraph; $raised = $card->raised_amount; $goal = $card->goal_amount; $link = $card->link; if ($raised == 0 ) : $percent = 0; else: $percent = $raised_amount / $goal_amount * 100; endif; if ($percent <= 5) : $percent = 0; endif; ?> <span id="card<?php echo $count?>" class="card"> <img class="cardThumb" src="<?php echo $img->url; ?>" alt="<?php echo $image->description; ?> Thumbnail" /> <div class="cardBody"> <div class="cardText"> <h2><?php echo $cardHeading; ?></h2> <?php echo $cardBody; ?> </div> <div class="progressBarSection"> <progress class="progressBar" id="progressbar<?php echo $count; ?>" value="<?php echo $percent; ?>" max="100"></progress> <span class="raisedAmount"> $<?php echo $raised; ?> usd </span> <span class="goalAmount"> $<?php echo $goal; ?> usd </span> </div> <div class="primaryBtn"> <a href="https://www.paypal.com/donate?hosted_button_id= <?php echo $link; ?> &source=url"> <button> <i class="fas fa-donate"></i> Donate </button> </a> </div> </div> </span> <?php } ?> Thanks in advance for any help!
    • By CachePuzzles
      Hi there,
      I'm probably missing something simple, but I'm just setting up my first site so I guess that's bound to happen.
      I've installed the LoginRegistration module and at first I was thinking that the confirmation emails weren't being sent. However I now see that new user confirmation emails are taking 20+ minutes to arrive. Is there a way to speed this up?
      Also the email is coming from processwire@mydomain - I couldn't found a place to change this.
      Any advice or help would be great!
      Brian
    • By fruid
      Hi friends,
      just 7 months ago, I was "just" a designer and a rather semi-developer, still struggling with WordPress sites and more often than not delegating that work to pros. ProcessWire really helped me realising that it's not that hard after all (well it's still hard but it's doable) and you learn a lot just by doing it which has to be true for all developers anyway. So I started coding myself, I might also have to thank the 2020 pandemic to help me focus a bit more than usual, I created a bunch of websites using PW already – one of which I can't wait to put on showcases but it's still not live yet. That is one big personal milestone for me. The next milestone would be to give something back, and so I'd like to take on contributing some code I wrote, namely a event calendar for anyone to use. It's my first attempt doing this so please don't eat me alive. It's not a PW module yet (that's the plan however) just a git but I'm positive it will be useful once it works – well it works but it still needs more work – because if I had found a module that came close I wouldn't have started coding it myself :D
      With that, I will appreciate all input, be it how to improve the .js (probably especially), or the templates, or guidance how to proceed turning this into a PW-module, and of course, in that last process, no pun intended, suggestions to make it more versatile for different needs.
      git: github.com/bbblgmsp/ProcessEventCalendar
      demo: http://foobar.roofaccess.org/events/
      Thank you!
    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
×
×
  • Create New...