Jump to content

kongondo

PW-Moderators
  • Posts

    7,379
  • Joined

  • Last visited

  • Days Won

    139

Everything posted by kongondo

  1. @Adrian, Sorry, my bad. I had some white space in my code... It works fine, thanks.
  2. @Adrian....I am getting unknown selector operator errors with your code (even when I match the ' and ". ) Btw, I have always had problems using these constant statuses within selectors; I can never seem to recall (or find) the right syntax. You are right, they are much easier to read than status numbers!
  3. Try this...quick and dirty...works for me...could be better/smarter/other ways... $articles = $pages->find('template=articles, parent.status!=2049'); 2049 = unpublished status...
  4. There's something called variable scope within a function....Basically, a function is a closed container and is not aware of its surroundings...It only knows the things within it. Hence, you need to show it the outside world. To do that, you need to use some sort of global variable...something that is powerful enough to see the 'outside' from 'within'....that thing in PW is wire So, you can either use: wire('pages')->get();//as a function/method //or $wire->pages->get();//as a variable The same issue of scope arises when dealing with modules/class or bootstrapping PW... By the way, you don't want to be echoing within a function....use return instead (at the end)...before that...you can save stuff that you will want to output in a variable...e.g. $out = ''; //do more stuff...then we add to $out.. $out.= 'this is my cool stuff'; //do more stuff, then append to $out. $out.= 'this is even better man!'; return $out;//you can also do return $out . $another variable . $foo . $bar, etc.. //Call your function and it will output what you return-ed in the function...
  5. Google (the web, not just this forums) "capturing form input html php" Read this http://processwire.com/api/variables/input/ This http://processwire.com/api/variables/sanitizer/ As well as Wanze's post above about passwords...
  6. Isn't that the normal practice globally? Also, define details? Some choose to send passwords and user names. Others just send user names and ask user to confirm their email address, blah blah... Spammers can be people or bots. If the former, you decide whether you check uniqueness by email or other method...As for the latter, search forums (or the internet) for "honeypot" in relation to forms ....there's other stuff out there too to help with spammers, some less effective (and/or more annoying!) than others.. Take your pick from these...http://processwire.com/api/variables/sanitizer/ . If nothing suits you there, you can roll your own Regex. You could should also start with client-side validation with some jQuery magic; no need allowing a user to submit a form with an invalid user name (or any other invalid input). BUT THIS IS no replacement for server-side validation! You must do that, e.g using your PHP and/or PW API stuff - e.g. $sanitizer....
  7. Adding to Wanze's code... $username = $sanitizer->pageName($input->post->username); $u = $users->get($username); if ($u->id) { $message = "Sorry, that username is already taken..."; } else { $u->addRole('frontend-editor'); $u->save(); } Assumes you already have that role available
  8. find will find many (or even all!) things if they exist unless you limit it. This will put a strain on your servers and PHP may even timeout. get, will only get one thing...so, less resource hungry. The general rule is that when using find, you need to use limit=xx. You can always paginate your results if you need more to be fetched. But, if you are sure that the number of children will not grow, and that you have a set reasonable number of children, then you can avoid the limit
  9. Using pages for selects: that's your most powerful relational database right there! It gives you access to the whole Page Object or Page Objects that are selected (hence everything about them)...you can even go farther down the rabbit hole...and find out more information about other relations that those selected pages have (other than their relation to the page that has the page field) - their parents, children, etc...This is a very powerful PW feature yet Ryan has implemented it as a very simple, user-friendly and elegant solution... I have never used Select AKA Dropdown - so, no comment...but, horses for courses...
  10. Help setting up a way to ask for a credit card first, then process the card for the payment, then post the page. This is probably the trickier one. I have no idea about credit card processing but there have been posts in the forums about processing payments, e.g. using paypal...Others can chip (no pun intended!) in here... I have re-read your post and see payment will be made via paypal. From what I have read in the forums (and I agree with that approach), if you can avoid it, do not handle, take or store credit card details on your site. There are "cheaper" payment gateways that can handle that for you....or redirect users to paypal. Let them deal with the security issues. Anyway, I don't know much about this area so search and/or wait for other responses Help redirecting the user to the newly created page after they have submitted the data through the form builder form. The potential issue with this is when two or more pages have been created at the same time. Creating a page via API is easy though. Redirecting is also easy: $session->redirect($url). I don't know how you are creating your pages but one way to grab the page created by "this particular visitor" is: You could get the sanitized name of the page and save that to a variable as you save the page. If the name has not been rejected, then use that name and the template of that page to grab the newly created page and use that as the $url variable in the $session method..e.g. something like....$pages->get("name=$name, template=my-template"); where $name is the sanitized value you saved in this variable before you saved the page [but only proceed with redirecting the user to the new page if one was actually created! So, you will have to check for a page id. If no id exist, the page was not created and you need to tell the user that]. You don't want to use title to get the new page since titles don't have to be unique. There could be other ways of doing it (using cookies and all that...) but the above is probably simpler...Others here will have better ideas ;-) Automatically create a user and password and assign it to the newly created page. I am not sure about creating a password. Why not ask the user to create their own password when registering? Then, save the page but as unpublished which you will then publish after you receive payment. In this case, there is no need to redirect the user to their newly created page. It is of no use to them anyway until they have made a payment they won't be able to log in. So, I would take them to a "thank you" page, awaiting confirmation and payment, blah blah message.... Creating a user is easy. Have a look at the API docs: http://processwire.com/api/variables/user/ Just my 2p
  11. Thanks Ryan! The grouping feature is really cool!
  12. Oh oh...This boy is on fire!!!! Good job @Horst!
  13. Oops, in my example, I had commented out //require_once('Googl.class.php'); This is because I had the Class already in my template file...Don't forget to uncomment yours! ...if you do, PHP will tell you anyway...
  14. Thanks Adrian, edited post....
  15. Having said that....in my tests, I have noticed that Google is intelligent enough to know if I have already created a short URL for a page if I am using the same API key...Attempts to recreate just give me back the same short URL it created earlier...Anyway...
  16. Edit: Here's some code. Note, I am using a URL field...works fine... if ($page->links) { echo "<p>The existing short url is :" . $page->links . "</p>"; } else { require_once('Googl.class.php'); $url = new GoogleURL('YOUR_API_KEY'); // Shorten URL $shortUrl = $url->shorten($config->httpHost . $page->url); $page->of(false); $page->links = $shortUrl;//this is a URL field $page->save('links');//we save only this field (see Adrian's post below) echo "<p>The shortened url is :" . $page->links . "<p>"; }
  17. Just a quick thought... You could create a field (e.g. a text field - just use a URL field called 'shorturl') and include that in your template for the pages that you want to have a short URL. Then, use an if statement to check whether the shorturl field is empty. If it is empty it means no short URL has been created, so include the Google URL shortener code. Once it creates the short URL, save the shortened URl in that text URL field (maybe it could be a URL field as well but PW would probably attempt to modify it ) and echo it out to the social share buttons. If the field is not empty, it means there is already a short URL, so just echo that one to the social buttons. Hope this makes sense Edit: Use a URL field; works fine - see below
  18. Hmm..you might want (if comfortable) to state upfront what your budget is and see what comes up...Or maybe you are getting PMs already...
  19. Hehe...this should be in the tutorials section ;-)....
  20. ...It only took 26 replies + 120 views + restarting a computer to resolve this..! Hehe... Glad u got it sorted... That looks pretty - well worth the effort
  21. Yes, for both 'checked' = 'checked' and where 'checked' has not been sent to the output markup, value = 1 [but you can set your own as Soma's says]
  22. I'm not sure I get you Martijn...I've tried with both evaluate to true and to false (i.e. $checked=0 and $checked=1) and works as expected. Edit: FWIW, I have not tested this in the context of ___getConfigInputfields.
  23. It works for me like this (just like yours) $checked = 1; $chx = $this->modules->get('InputfieldCheckbox'); $chx->attr('id+name', 'delete'); $chx->attr('checked', ($checked === 1 ? 'checked' : ''));//works also with simple == $chx->label = $this->_('Delete'); //more code then render... $m->attr('value', $chx->render());//$m = InputfieldMarkup //output <input type="checkbox" id="delete" name="delete" value="1" checked="checked"> If the checked attribute is blank (i.e. if it does not evaluate to 1) then checked attribute is not output in the resulting markup. Is that what is biting you? if your fname returning false? Edited: to add checking $checked variable; to show (newbies) the markup output
  24. Just to add (I feel like typing today!)... You don't need to create a module unless you want something portable (or cool! ). I had a feeling you wanted to hide your "themes" page from other users maybe...there you go, Joss gave you an answer... I must admit I was very tempted to quickly rustle up a PW-Zen-garden-like site to show you how easy it is to do what you requested ...
×
×
  • Create New...