-
Posts
450 -
Joined
-
Last visited
Community Answers
-
bwakad's post in pages find - dynamic none, static all was marked as the answer
I have tried both from Soma and Diogo - not working.
In this case, they both should reflect "/browse/". Using static works, dynamic not. Strange.
I just used $page->parent->children - not working either...
But since I do not want to restrict myself only to /browse/ I thought to use page parent.
So this static path is working.
<?php $navigation = $pages->find("parent=/browse/");?> $page->prev($navigation)->url - EDIT - stupid!!!
I forgot, in my old code - I used echo strings : echo "<div><a href='$page->prev($navigation)->url'>Link here</a></div>";
This time I used <a href="<php $page->prev($navigation)->url;?>" (without echo)...
Sorry all, thought suddenly something was wrong with my PW.
-
bwakad's post in SessionLoginThrottle was marked as the answer
Got it (must be halfblind). Sorry for that. It now displays nicely in a container at top of the form.
try{ $u = $session->login($username, $password); if($u && $u->id) { $session->redirect("/members"); } } catch(Exception $e) { $errorMessage .= "<li><b>" . $e->getMessage() . "</b></li>"; } -
bwakad's post in submit form and PW error message was marked as the answer
Thanks, I did it like code below. Had to set (novalidate in my form tag) to test. - EDIT - see also topic SessionLoginThrottle
Now, with an empty field is does not matter.
But if I check on username (taken), or values based on pregmatch, these values are not sanitized until all is good. Those could be a problem.
Should I move the sanitize, or do I use a double sanitize ? Don't know if PW allows double sanitize...
if ($input->post->submit_registration) { $errorMessage = ""; // check field and add message to variable if (empty($input->post->myfield) ) { $errorMessage .= "<li><b>myfield</b> is empty.</li>"; } if ( empty($errorMessage) ) { // form details are okay, do my thing } } // before I display the form if ( !empty($errorMessage)) { echo "<p>There was an error with your form:</p><ul>" . $errorMessage . "</ul>"; } // start form here <form action='./' method='post' id='someid' novalidate> // field, and retrieve invalid value back <input type='text' name='myfield' value='<?php echo $input->post->myfield; ?>' id='myfield' /> -
bwakad's post in addresses... more or less was marked as the answer
I am happy! at least for now...using the google api3 autocomplete through a plugin.
Now my form has:
- address field, which autocomplete as soon as someone starts typing.
- 3 disabled input fields, that automatically catch this input as Country, Division and City, before submitting the form.
Upon submit, I can now:
- check if these values exist as a page, and if not, create it - OR - simply use these values in a member profile field. (have to deside on this)
- Do I really need to create pages for this I can search by $page->name/title OR by $field->value...
Benefit of the API
- that it can also check a users location. For instance, if I had a user providing information like being in USA, but according to API is in Europe...
- I could simply catch this value hidden, and display this value on it's profile saying "false location provided ....etc".
-
bwakad's post in Page Reference Field ? was marked as the answer
Okay, so what I understand is:
1.
I need to create the field,
choose Page,
select a parent-page,
then choose single. multi, or any other...
2.
I then add it to the template.
3.
Go to the page I want to add page reference to
4.
and select the pages that need referencing.
---
-
bwakad's post in Hide certain menu items for members or guests was marked as the answer
Well, since there is not really an easy way of doing this from admin side, I made special pages not visible. I then use this code in my functions.inc :
if(!$user->isLoggedin()) {
$menu = "string-with-markup-and-my-links-for-guests"; // login or register
} else {
$menu = "string-with-markup-and-my-links-for-users"; // edit-profile or change-pass
}
In head.inc I use this in the section part of the top-bar: echo $menu;
Special pages use my template: credentials.php. The page "Credentials" is not visible but still accesible. The template has a switch() to determine what get's included.
Because of the switch() I can set a default case if no other one get's included. And inside this default, I simply give some instructions and information about other stuff.
So much fun to play with PW!
-
bwakad's post in user related fields per template - what is secure? was marked as the answer
Martijn, you are really good. I see that was quite more then a normal login. It works! Since I am using this in a modal (foundation) and this modal closes when submit is clicked. is it possible (in case of errors) to redirect and echo these errors?
ps. I have corrected some typos: missing ; and } at some places:
<?php $email = $sanitizer->email($input->post->email); $password = $input->post->password; $amount = $pages->count("template=user, email=$email, include=all"); // if we have only one user with this email address, give the username back if ($amount === 1) { $username = $users->get("email=$email, include=all")->name; try { $u = $session->login($username, $password); if($u && $u->id){ $session->redirect("/login"); } else { $errors = "Login failed."; } } catch(WireException $e){ // throttle login $errors = $e->getMessage(); // get the error message $session->redirect("error-page"); ----------------- on that page echo $errors } } elseif (!$amount) { // no account with this email address } elseif (!$email) { $errors = "Not a valid emailaddress"; } else { // multiple user accounts $errors = "Login with username instead."; } ?> -
bwakad's post in find vs get - page exist true or false was marked as the answer
Thanks Diogo / Soma !
I had to combine your replies into 1, or combine Soma's with your's. To make this short, I am testing to see if a page really exist.
Using get I need to add ->id, otherwise I am getting a false positive/negative (returning NullPage).
Using count() without ->id, otherwise that last is property of non-object (if page exist or not).
get() with id
if($pages->get("parent=/contracts/, name={$contract}")->id) { echo "found"; } else { echo "not found"; } count() without id
if($pages->count("parent=/contracts/, name={$contract}")) { echo "found"; } else { echo "not found"; } -
bwakad's post in link on range field and find pages was marked as the answer
Solved it by (again!) study php on lynda.com... I simply had to send the value through url (I think because the value is not a page)...
My pages can all be browsed by the browse.php template.
This template has only one function echoed out.
That function determines what the page id is, then create the selector, then include the browse.inc for layout.
In short, all my displayed field values are links to search the way which I control by the function.
Displayed link on browse.inc is this code (sorry if its not clearly readable):
// store value in variable $min = $child->uren->min; //in the link I send the value through url with ?min=xxxxx <a href="<?php echo $config->urls->root; ?>/uren/range/?min=<?php echo $min;?>"><?php echo $child->uren->min;?></a> In my function I use this
case '1192': // id of current page $min = $_GET['min']; $selector = "template=child-template, uren.min>={$min}, sort=uren"; break; // later on I use $selects = $pages->find($selector); // then include file for display again include("browse.inc"); Great to study php!
-
bwakad's post in difference Select AKA dropdown vs Page field type? was marked as the answer
You all explained very good. I think sometimes I still have issues thinking other CMS wise... Have to forget about limited CMS's, and start thinking PW ;-)
So I will close this topic as answered.
-
bwakad's post in select - default value was marked as the answer
Although a default value for 1 single select works, it does not work on dynamic single selects. The only way I could solve this was to take out the default value for the first select. Then on the second select I used: Show this field only if province!=''
On a new page where fields where not chosen, and on edit page where fields where added after creating the page:
First field (province) shows blank and full width. And when choosing a value; second field (municipal) shows blank and full width.
And in template files I don't have to worry about default value because fields are required before saving.
Note! would be nice if developers just remove the default value at back-end to avoid confusion!
-
bwakad's post in Page ID# is not valid for Field-Name was marked as the answer
Okay - I checked settings for this last field... it turns out it was set to multi page array. After changing to single page (null) it will at least accept changes. I did install a fresh DEV-branch and work from that. Just so things are more readable for now.
But now a new problem: that I need to save one time for 'province' to be written to DB, and another time for 'city'. Even though I made it in one change - I have to save two times....
Solved (see fields section)
Page levels from root:
- about
- location
- - province-one
- - - city-one
- - - city-two
- - province-two
- - - city-three
- - - city-four
Since they are used for selects, I just created their templates without a file. e.g. location, province, city.
I also made 2 fields: select_province, select_city.
select_province
type = page
dereference = single/null
required = yes
default value = 1015 = id province-one
selectable pages parent = location
input field type = select
select_city
type = page
dereference = single/null
required = yes
show this field only if = select_province!=''
custom selector = parent=page.select_province
input field type = select
I added these 2 fields on the template (basic-page), and when I edit about (basic-page) and select a province, I get their respective cities in select_city and select one there.
When opening the page where this fields are added (on-load),
if it was a new page where fields would be empty - it will have a populated select_province, and also a select_city; if it was filled in before - have a chosen select_province, and also a chosen select_city. Does anyone have suggestions to make it better? Like maybe a default value as a text?
-
bwakad's post in _init _main and basic-page was marked as the answer
Just to make it myself more clear I installed skyscapers in another localhost folder - and it almost make more sence to me.
Regarding the _out.php file, does this code mean the url is set to root and just append the hardcoded text cities after it? Where does it get the / from the browser url just after the root?
<li><a id='topnav_cities' href='<?php echo $config->urls->root; ?>cities/'>Cities</a></li> It then goes to cities.php
include("./browse.php"); and as it says include browse.php
$headline = "Skyscraper " . $page->title; $browserTitle = $headline; $content = $page->children("limit=100")->render(); The first two lines are obvious to me, but the third one is a question... how is the sytem knowing it need to collect cities pages - in this case? Is this because of $page represents "cities" from the url in _out.php?
Seeing how this Skyscrapers is working I guess I have to make seperate template files for each entry:
jobs - province // in admin template with fields:
- city
- company
- branche
- skill
jobs - city // in admin template with fields:
- province
- company
- branche
- skill
jobs - branche // in admin template with fields:
- province
- city
- company
- skill