Jump to content

webhoes

Members
  • Posts

    233
  • Joined

  • Last visited

Everything posted by webhoes

  1. Hello, I have a field tests on a page. These are checkboxes. I created the following code in ready.php to make them visible, but it doesn't work. It should show all tests that belong to the same customer ($page->parent->parent). I get the following error: Unknown Selector operator: '' -- was your selector value properly escaped? $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'tests') { $currentPage = $event->arguments('page'); //current test page $rootParent = $currentPage->parent->parent; //project page // $rootParent = $currentPage->rootParent; $testParent = $rootParent->child('template=user-stories'); $tests = $testParent->children('template=user-story'); //all tests of that project $event->return = $event->pages->find($tests); } }); My page tree is like this: Home - Customer 1 (template customer) -- Tests (template tests) --- Test 1 (template test) --- Test 2 -- User stories (template user-stories) --- User story 1 (template user-story) --- user story 2 - Customer 2 -- Tests --- Test 1 -- User stories --- User stories 1
  2. Hello, I have the following in mind. I want to make a tree of customers with user stories as childs. Each user story has a title, body with general description and repeating fields for every step to test the user story (go..., click on, etc). Every steps needs to have a boolean for passed or not. Also every user story has one (or more) scope (back-end, front-end, portal, filter, etc) Home - Customer 1 -- User story 1 -- User story 2 - Customer 2 -- User story 1, etc So far not diffucult. I also want to generate tests. Home - Tests -- Test 1 Customer 1 20182601 (title) -- Test 2 Customer 1 20182501 -- Test 3 Customer 2 20182501 By adding a new test I want to enter the title and on the next page fill in some general fields and the customer and scope. Based on the last 2 fields and want to see on the page of the test all tests with steps for that customer and scope. This is also pretty ease to output but I can not figure out how to save the data for that test in the database. So all the test steps with the boolean that belong to that particular test. A user story can be tested in multiple tests on different moments, so the boolean on the user story page does not represents the one in the tests. Any advice?
  3. I see now... did not read carefully enough though the whole thread...
  4. Something like this <nav class="uk-navbar-container" uk-navbar> <div class="uk-navbar-left"> <ul class="uk-navbar-nav"> <?php $root = $pages->get("/"); echo "<li><a href="/">Home</a></li>"; foreach($root->children as $child){ echo "<li><a href=" . $child->link . ">" . $child->title . "</a>" if(count($child->children>0)){ echo "<div class="uk-navbar-dropdown uk-navbar-dropdown-width-2 g8-theme-mkred"> <div class="uk-navbar-dropdown-grid uk-child-width-1-2" uk-grid> <ul class="uk-nav uk-navbar-dropdown-nav">"; foreach($child as $c) { echo "<li><a href=" . $c->url . ">" . $c->title . "</a></li>"; } echo "</ul>"; } } ?> </ul> </div> </nav>
  5. In both cases you add $root (home or page 1) to the array. That is why they appear. You could hardcode the link to home and after that make a foreach for the children of $pages->get("/"). You don't have to do fancy tricks to add home like and or prepend.
  6. This is the efficient version. By using substring I avoid creating new page arry in the foreach loop. <?php $text = ""; foreach($page->verspreidingen as $country){ // all countries $text .= "<a href='". $country->url . "'>" . $country->title . "</a>"; $s_out = null; foreach ($page->sub_verspreiding as $state) { // foreach state on the page that is child of a country if ($state->parent == $country) { $s_out .= "<a href='". $state->url . "'>" . $state->title . "</a>, "; } } substr($s_out, 0,-2); if(isset($s_out)) echo " (" . $s_out . ")"; $text .= ", "; } substr($text, 0,-2); echo $text; ?>
  7. This seems to work Perhaps it could be more efficient. <?php foreach($page->verspreidingen as $country){ // all countries echo "<a href='". $country->url . "'>" . $country->title . "</a>"; $s = null; $s_out = null; $states = null; $sarray = new PageArray(); foreach ($page->sub_verspreiding as $state) { // foreach state on the page that is child of a country if ($state->parent == $country) $sarray->add($state); } foreach($sarray as $s){ $s_out .= "<a href='". $s->url . "'>" . $s->title . "</a>"; if($s != $sarray->last()) $s_out .= ", "; } if(isset($s_out)) echo " (" . $s_out . ")"; if($country != $page->verspreidingen->last()) echo ", "; } ?>
  8. Totally overlooked this I will give it another thought tomorrow and apply better logic
  9. Yes, that is the way it should be. But I also get all states of that country (child/parent relation) even is they are not selected on the page.
  10. Thanks for the link @kongondo With parent=page.verspreiding When I output is in the template I do get something wierd. I expect the output to be like: Afghanistan, China, Mexico(Campeche, Chiapas) but I get Afghanistan, China, Mexico(Campeche, Chiapas, Oaxaca). I get all children, not just those I selected on the page. <?php foreach($page->verspreidingen as $item){ // all countries echo "<a href='". $item->url . "'>" . $item->title . "</a>"; if(count($item->children) > 0 ){ // states of a country echo " ("; foreach ($page->sub_verspreiding("has_parent=$item") as $sub){ // foreach state on the page that is child of a country if($sub == $item->children->last()) { echo "<a href='" . $sub->url . "'>" . $sub->title . "</a>";} else { echo "<a href='" . $sub->url . "'>" . $sub->title . "</a>, ";} } echo ")"; } if($item != $items->last()) echo ", "; } ?>
  11. Hello, I am struggeling with the following. It concerns adding new content in the backend of the site. I have a template region with two fields. Country and provence wich is a child of country. Country is an amselect on the region template. I can select one or more countries. Now I would like to see only the children of selected countries (is present) in the selectbox provence. I looked at the possibilities of the query, but could not quite figure it out. Any tips?
  12. Ahaa... I meant ofcourse <pw-region> </pw-region> If I understand correctly I still have define the html in the different templates. That would not be different from what I have no (not they way described above). If there is a structural change in the template, I need to change them all. In my case every template has the same basic layout but different content that is outputted with a function where I render the layout of that specific content. That's why I was thinking of defining a region for the layout and within that a region for the content. To seperate the layout and the content. I just playing with the possibilites and hope to get to use them clever.
  13. Hello, I am playing with pw-regions. Normally I make a _main.php with the basic layout with a content region. For templates that need a different content region I override the complete content region that includes basic layout and also make a copy of the sidebar. Side effect is that if I change the sidebar I need to change it on several templates. Now I am working on this. Now _main.php I make two body regions (body and body-sidebar). One with sidebar and one without. Within these regions a make region content and a region sidebar. //without sidebar <pw-regiond id="body"> //some html <pw-regiond id="content"> //some html </div> //some html </div> //with sidebar <pw-regiond id="body-sidebar"> //some html <pw-regiond id="content"></div> //some html <pw-regiond id="sidebar"> //some html </div> //some htm </div> On the other templates I output a specific content through the content region done by functions. If I don't need a sidebar I override the region <pw-region id="body-sidebar"> with nothing. If I do need a sidebar I override <pw-region id="body"> with nothing. The content regions always outputs in the visbile body in the conent region. Also the sidebar is a region (sidebar). If outputted I can append or prepend to it. I works but is it a correct method. I am currious to know if this slowsdown the side because of extra rendering. What could be other strategies to get this flexibility?
  14. Hello, I want to make a from that allows a site visitor to add a sighting. They should enter location (name of the page), a acountry (from select), a subspecie (from select), a remark (text). Also but not implementend a location with leaflet module and a image. Not sure how to do that yet. This is what I have. I already creates a new page on refresh and also only takes the correct template. pagename and other fields are not passed. Please help me to correct this. <h4>Add a sighting</h4> <form method="post"> Location <input type="text" name="name"><br> Country <select name="country"> <?php foreach($pages->get(1022)->children as $country) { echo '<option value="' . $country->id . '>' . $country->title . '</option>'; } ?> </select> Subspecie <select name="subspecie"> <?php foreach($pages->get(1027)->children as $subspecie) { echo '<option value="' . $subspecie->id . '>' . $subspecie->title . '</option>'; } ?> </select> Remark <input type="text" name="body"> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> <?php $p = new Page(); $p->setOutputFormatting(false); $p->parent = $sanitizer->selectorField($_POST['country']); $p->template = 'population'; // example template $p->title = $sanitizer->pageName($_POST['name']); $p->name = $sanitizer->pageName($_POST['name']); $p->body = $sanitizer->text($_POST['body']); $p->save(); echo "page ID {$p->id} created!<br>"; ?>
  15. Thanks @netcarver, that works. I got it working with a switch statement. Not neat but it works. This solution is much neater.
  16. As far as I know the documentation says you should change the /sites/config.php. This also generates double output for me. That never worked for me. I change /wire/config.php. Downside is that with every update I would need to change it again.
  17. Hello, I am trying to get a full map with different marker colors. I use the following code (based on the documentation on the github page). But they keep being the standard blue. <?php $items = $pages->find("template=population"); ?> <?php $options = array( 'markerFormatter' => function($page, $marker_options) { $marker_options['markerColour'] = $page->subspecie->population_color_name; return $marker_options; } ); ?> <?php echo $map->render($items, 'location', $options); ?> for a single page with template population I got it working. That is the code below. <?php echo $page->subspecie->title; ?> <?php //$map = wire('modules')->get('MarkupLeafletMap'); ?> <?php $iconColor = $page->subspecie->population_color_name; ?> <?php echo $iconColor; ?> <?php echo $map->render($page, 'location', array('height' => '500px','markerColour' => $iconColor)); ?> Just not for the page with all populations. What I am doing wrong?
  18. Those are very clear answers. Thanks Currently all functions are specific to a site as they also contain small parts of the template. I do see stuff coming in the future that could be used in more sites. By then I should make it a module. Making a module would be the next challange to learn.
  19. Hello, A general questions. A recently made a tag cloud for my website. I looked at an old module for that and based on that logic created a function in my _func.php. It contains a fourth of the code and does the same. I am curious in wether there a great differences in doing something via a function or making a module for it. Specially the pro's and cons for each like speed, maintainability or what is best practice. Sanne
  20. Thanks @Zeka I disabled caching post variables. It seems to work nog. @rafaoski your are right to use sanitizer. I will change that too. There is already a namespace on top of _main.php. My code is also in _main.php. Did you put the code in another file (template)?
  21. Hello, I noticed an issue with my mail form. When I am logged in it works. When I am not logged in it doesn't work. The templates are chached so I presume it must be that. Below is my code. Could it be cache or something else. And more important, how to should I fix this. <?php if (isset($_POST["submit"])) { $result = '<div class="alert alert-success">Form submitted</div>'; if (!$_POST['name']) { $error = "<br />Vul je naam in"; } if (!$_POST['email']) { $error .= "<br />Vul je emailaddress in"; } if (!$_POST['comment']) { $error .= "<br />Vul een opmerking in"; } if ($_POST ['email'] != "" AND !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $error .= "<br />Gebruik een geldig emailaddress"; } if (isset($error)) { $result = '<div class="alert alert-danger"><strong>Da hej mangs, er is iets niet goed ingevuld:</strong> ' . $error . '</div>'; } else { $message = $mail->new(); $message->subject('mail via webhoes.nl') ->to('sanne@webhoes.nl') ->from(strip_tags($_POST['email'])) ->fromName(strip_tags($_POST['name'])) ->body('Name: ' . strip_tags($_POST['name']) . "\r\n" . 'Email: ' . strip_tags($_POST['email']) . "\r\n" . 'Comment: ' . strip_tags($_POST['comment'])); $numSent = $message->send(); $result = '<div class="alert alert-success"><strong>Bedankt voor je email. Wij nemen zo spoedig mogelijk contact op.</strong></div>'; } echo $result; } ?> <!-- Button trigger modal --> <!-- Modal --> <div class="modal fade slide left" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button> <p class="modal-title" id="myModalLabel">Contact met Webhoes!</p> </div> <div class="modal-body"> <p class="lead">Laat wat van je horen!</p> <form method="post" id="myForm"> <div class="form-group"> <label for="name">Naam:</label> <input type="text" name="name" id="name" class="form-control" placeholder="Name" value="" required/> </div> <div class="form-group"> <label for="email">Email:</label> <input type="email" name="email" id="email" class="form-control" placeholder="Email" value="" required/> </div> <div class="form-group"> <label for="comment">Opmerking:</label> <textarea class="form-control" id="comment" name="comment" required></textarea> </div> <input type="submit" name="submit" class="btn btn-success btn-lg" value="Verstuur"> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-error" data-dismiss="modal">Annuleren</button> </div> </div> </div> </div>
  22. I usually use this code (sometimes changed for some specific needs). I have installed the wiresmtp module and the mail gets send through that module. The form is a bootstrap modal that pops up. <a href="#myModal" data-toggle="modal" data-target="#myModal">Contact</a> This is a version that only uses 1 to email. <?php if (isset($_POST["submit"])) { $result = '<div class="alert alert-success">Form submitted</div>'; if (!$_POST['name']) { $error = "<br />Vul je naam in"; } if (!$_POST['email']) { $error .= "<br />Vul je emailaddress in"; } if (!$_POST['comment']) { $error .= "<br />Vul een opmerking in"; } if ($_POST ['email'] != "" AND !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $error .= "<br />Gebruik een geldig emailaddress"; } if (isset($error)) { $result = '<div class="alert alert-danger"><strong>Da hej mangs, er is iets niet goed ingevuld:</strong> ' . $error . '</div>'; } else { if (wireMail("putyouremail@here.com", $_POST['email'], "Mail van de website website!", "You have an email from the website contact form\r\n", " Name: " . $_POST['name'] . " Email: " . $_POST['email'] . " Comment: " . $_POST['comment'])) { $result = '<div class="alert alert-success"><strong>Bedankt voor je email. Wij nemen zo spoedig mogelijk contact op.</strong></div>'; } else { $result = '<div class="alert alert-error"><strong>Da hej mangs, er is iets niet goed gegaan!</strong></div>'; } echo $result; } } ?> <!-- Button trigger modal --> <!-- Modal --> <div class="modal fade slide left" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button> <p class="modal-title" id="myModalLabel">Contact met Webhoes!</p> </div> <div class="modal-body"> <p class="lead">Laat wat van je horen!</p> <form method="post" id="myForm"> <div class="form-group"> <label for="name">Naam:</label> <input type="text" name="name" id="name" class="form-control" placeholder="Name" value="" required/> </div> <div class="form-group"> <label for="email">Email:</label> <input type="email" name="email" id="email" class="form-control" placeholder="Email" value="" required/> </div> <div class="form-group"> <label for="comment">Opmerking:</label> <textarea class="form-control" id="comment" name="comment" required></textarea> </div> <input type="submit" name="submit" class="btn btn-success btn-lg" value="Verstuur"> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-error" data-dismiss="modal">Annuleren</button> </div> </div> </div> </div> Last week I made a version that took an emailid (first part of the email) with js. On send it combines the first part to the domain to create the to emailadress. It is my way of not reveiling the email to the general public. It works, but some additional security checks could be added.
  23. You have two stand alone queries with no relation between them. Tag_code is not relating them in this case. You should do something like this... $cities = $pages->find("template=t3Cities_list, sort=title"); foreach ($cities as $c){ echo <div class="row">' . $c->title . '</row'; foreach($c->tag_code as $t){ echo $t->title . ' | '; } } I usually make it a function in _func.php
  24. Yes, ofcourse. But as @SamC said. Why not make the whole site in PW. It will cost a little time, but you'll have even more flexibility than with a static site.
×
×
  • Create New...