-
Posts
6,803 -
Joined
-
Last visited
-
Days Won
159
Everything posted by Soma
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
Thanks Matthew, well I like all good beers Have you tried my suggestion to output the upload path to debug? However, to make it short, Ryan made an small error in that he uses "$config" in a function scope. That would leave you with a upload path "temp". It would have to be "wire("config")->paths->assets" to get it to work, as wire() is global and can be used everywhere even in functions.- 84 replies
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
Confirming means you tested it? Echo it out in your code and add line "exit;" after it.- 84 replies
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
And what do you think it is? What have you done to debug the upload path, now that you know it's something wrong there? The answer is even in the error itself.- 84 replies
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
If you create a new child page, which can have multiple templates, the creating page process can't know which template you gonna choose. So it doesn't work the way you doing. Also in this case it wouldn't make sense as you don't know which template context should be displayed. BUT if you have a setup where the parent page template only allows for 1 particular child template (under Family settings of parent template) it does take that template for the page creation step and you'll see the title in context. The "name" field is built-in and a special field you can't change within fields setup. But you can have a simple autoload module that renames the label to what you like. Although I think it's not an issue to have it "name", I understand people want to name it different. A module like the HelloWorld.module, can be used as a starting point, with as hook and a function // in init() method add a hook $this->addHookAfter("InputfieldPageName::render", $this, "hookPageName"); and add a function below with this: public function hookPageName(HookEvent $event){ $field = $event->object; $field->label = "URL segment"; }
-
Just wanted to share that, when using pages find to search title|headline|body, since the body usually is text which contains html the search also finds html elements within text. http://processwire.com/search/?q=strong The pages found do not contain the word strong. I know searching pages using a pages->find(selector) does not account for this, but maybe one should clean all those tags out, or add it to stop words? Stripping tags before a search on texarea? Searching site with PW in genreal How do you guys also feel about using pages->find() to use as a site search? In cases where data pages are is pulled into other pages, it's getting hard to work around those cases and keep track of it. Also sometimes it seems the search doesn't return pages in correct relevance, depending on a lot of factors what fields you search and if they're full text etc. What is you're experience with PW search? If you use multilanguage, the stopwords are still only the english once used that come with core. So not ideal still. What you guys think about having a search tool to index pages using a parser and write index tables? Or would you use another tool or google custom search?
-
http://processwire.com/talk/topic/941-accessing-values-from-%E2%80%9Cparent%E2%80%9D-template-when-page-is-rendered-within-another-template/ http://processwire.com/talk/topic/1510-templatedisplay-mode/ There's more but can't find. So you can also do: $somepage->contextpage = $page; echo $somepage->render(); And in the $somepage template if($page->contextpage->id == 1001){ ..
-
jQuery and UI is required for the admin to work. Some inputs like images and ASM select etc. are depending on jquery and do not work without.
- 7 replies
-
- javascript
- js
-
(and 1 more)
Tagged with:
-
Customize List of Fields to display in Admin Page.
Soma replied to Luke Solar's topic in General Support
Maybe this is even better http://modules.processwire.com/modules/template-decorator/ -
http://processwire.com/api/cheatsheet/?filter=login&advanced The InputfieldPassword::matches isn't in there since it was also not in API documentation and also belongs to the InputfieldPassword module which is not part of the cheatsheet. Not every method there is is on the cheatsheet, lots of more advanced stuff is left out. Soon we gonna add new stuff that's added recently in 2.3.
-
You can do this: if($user->pass->matches("yourpassword")){ // correct } But normally you just login and if it fails you know it's wrong. if($session->login("nam","password")){ // logged in }
-
You better all come to the irc #processwire chanel. ;-)
-
Thanks for the report Manfred! Must have had nervous fingers when editing in there. Will remove the double in the next update. Because it's not easy possible to style the file field across browsers. I'm progressively hidding and adding new text and button using jQuery. Since there's no text translation for the file upload buttons (it's translated by the browser), I had to somehow make it possible to localize it.
-
Only if the template is in templates/ folder it works with both. But got caught on it on subfolders.
-
It would be with the complete path $page->template->filename = $config->paths->templates . 'summary.php'; $page->render();
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
So you got scared by that long complex basic form script? Creating form using ProcessWire as a framework and it's form and inputfield capabilities. Yes this would be possible and it's the way I use to make forms in front and backend whenever possible. Then we are finally here http://processwire.com/talk/topic/2089-create-simple-forms-using-api/ where I explained how to do it along with some examples. Yet another form example Since uploading files is a little special I went ahead and tried using the InputfieldFile to upload images to the temp folder and finally create a page and add those images same way as in the other examples. Then after success delete the temp files. Now this example does all the previous "pure" php example does, just using PW forms API. - required fields - CSRF preventing - inline error Form example snippet: https://gist.github.com/somatonic/5236008 There's also a CSS file example to style the form, and for example hide the "Drag files here...". This technique is the most simple to make front-end forms, and doing it this way allows you do add hooks to the form in case you need a custom validation or anything directly from within the template code. For example, the $form can be used to attach any hooks to the form: /* form hook example */ function hookEmail($event){ $file = $event->return; echo "email value: ". $file->value; } $form->get("email")->addHookAfter("processInput", null, 'hookEmail'); --- Little change to InputfieldFile.module to throw error if maxFiles is reached It works all well, but the maxFiles setting doesn't throw an error message when you choose more images than allowed. Since the InputfieldFile module is usually ajax based, it throws error via ajax and thus not in $form->getErrors() at all. It just proceeds and uploads only the max files and skips the rest. This could be changed in the module to also throw error on the field when no ajax is used. For this to maxFiles error to work I changed the /wire/modules/Inputfield/InputfieldFile.module a little: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module#L288 From: if($this->config->ajax) foreach($ul->getErrors() as $error) { $this->ajaxResponse(true, $error); } To: if($this->config->ajax) foreach($ul->getErrors() as $error) { $this->ajaxResponse(true, $error); } else { foreach($ul->getErrors() as $error) { $this->error($error); } } Maybe if Ryan can implement those to the Inputfieldfile to allow for front-end error to be shown, it would be great.- 84 replies
-
- 4
-
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
Thanks Ryan for the heads up, there's some nice examples for advanced coders. Strange. Now, I also would have thought that with !$u->getErrors() it wouldn't work, but it still does! I went and did many tests after you posted this and I can't see any difference and it all works as it should. The code works with both and I haven't looked into it further (core). I wish to be proven wrong but it really does (at least for me here) :/ I think you got a valid point with checking for if there's files really uploaded at all... However this wouldn't work if image upload would be not required in your form. Also the example you posted is also not showing how you could make required fields and inline error/repopulating fields, prevent CSRF and double posts. It's still a great example but as said, not a "complete" example that can be used in a public front-end form. May or may not suiteable for people not knowing what they're doing and only copy paste. What I also think could be the problem on Matthews side is that the PHP upload and post max size isn't enough to upload the file. I also tested this and it seems to fails silently with no errors and just shows the form again. Maybe there's a way to get around it, but thought it might be an issue since there's no error thrown as it's apache upload interrupting? --- It can get somehow complex to add all checks and validation to a form server side, and the following post example is also just for showing what all there's involved to make a pure php form (using some PW internals). Yet another example I've spent couple hours creating a form upload example - with files (images) upload to a page file field - adds new page on the fly and adds uploaded images - prevents CRSF attacks, this also prevents double post by refresh page after submit - has required fields with error messages inline - repopulates form field in case an error happened or a required field was not filled in - sanitizing and saving values to a page - jquery example with disabled submit button on form submit The gist repo can be seen here https://gist.github.com/somatonic/5233338 You can configure some variables and array's at the top and add remove fields as you wish to the html form markup. Like this: // --- Some default variables --- $success_message = "<p class='message'>Thanks for your message!</p>"; // --- All form fields as nested array --- // using html form field name => template field nam, from the page you're going to create $form_fields = array( 'fullname' => array('type' => 'text', 'value' => '', 'required' => true), 'email' => array('type' => 'email', 'value' => '', 'required' => true), 'message' => array('type' => 'textarea', 'value' => '', 'required' => true), 'newsletter_subscribe' => array('type' => 'checkbox', 'value' => 0, 'required' => false), 'images' => array('type' => 'file', 'required' => true) ); // --- WireUpload settings --- $upload_path = $config->paths->assets . "files/.tmp_uploads/"; // tmp upload folder $file_extensions = array('jpg', 'jpeg', 'gif', 'png'); $max_files = 3; $max_upload_size = 1*1024*1024; // make sure PHP's upload and post max size is also set to a reasonable size $overwrite = false; // --- Page creation settings --- $template = "upload-entry"; // the template used to create the page $parent = $pages->get("/uploads/"); $file_field = "images"; $page_fields = array('fullname','email','message','newsletter_subscribe'); // $page_fields = define the fields (except file) you want to save value to a page // this is for the form process to populate page fields. // Your page template must have the same field names existent // ------------------------------ FORM Processing --------------------------------------- include("./form-process.php"); To set this up. 1. Create a template upload-entry used to save the form submissions. With all the fields you'll have in the form, and name them the same as in the $form_fields 2. Create a form-upload.php template used to hold the form config and markup code: (create a template in PW with this name and the page the form should be rendered) https://gist.github.com/somatonic/5233338#file-form-upload-php 3. Create a form-process.php file in the templates folder with the processing code (This is included in the template file above after the configuration part) https://gist.github.com/somatonic/5233338#file-form-process-php There's a basic styling CSS: https://gist.github.com/somatonic/5233338#file-form-css And the jQuery snippet used to prevent double posting when double clicking the submit. https://gist.github.com/somatonic/5233338#file-form-js This is some screen showing the form:- 84 replies
-
- 7
-
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
Why so complicated? It's in jQuery $('body').on("dblclick", function(){ alert("double clicked"); }); Ah, just read again: click and double click on same. It does work with both.
-
Need some help with making a news section with archives
Soma replied to santaji's topic in Getting Started
Look at the error. Something with your selector is wrong. The limit has some whitespace that is not allowed. Should be limit=10. -
NIce solutions. I would solve it differently and not work against the natural structure but anyway. 1st world problem However up to you, if you feel happy with it, ok. Wanted to point out that you should write: 'outer_tpl' => '||', Or it will throw a notice in debug mode and I think it may result in not closing or opening tag (maybe not)? It's expecting a || to split for the template to use. Well better just add it.
- 9 replies
-
- navigation
- children
-
(and 1 more)
Tagged with:
-
I have to say when I first installed it also took a time to realize to change text and save before seeing an icon. But if I remember correctly I had to save and change 2 times to get it show up, is that intended? I think it would be better to show the icon from beginning to avoid confusion, and show a little text edit: too slow...
-
Ehi who the hell is adam?
-
Right with this structure it would look like this: <details class="pw-toc" open="open"> <summary>In this article</summary> <?php $treeMenu = $modules->get("MarkupSimpleNavigation"); $options = array( 'max_levels' => 1, 'current_class' => 'current', 'outer_tpl' => '<ol>||</ol>', 'show_root' => true ); $root = $page->parents->count == 1 ? $page : $page->parent; echo $treeMenu->render($options, $page, $root); ?> </details> The root here is found by counting what level, and either take parent or page itself as the root. -- You could also define root alternatively like maybe depending on the structure and templates: $root = $page->parent->template == 'article' ? $page->parent : $page; echo $treeMenu->render($options, $page, $root); So saying if parent page template is 'article' take current page->parent as root, if not we take current page assuming it's the top 'article' page and not a child.
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
Yes it works. Page is added and image is saved to page. Working example is here: https://gist.github.com/somatonic/5207537- 84 replies
-
- 1
-
-
- forms
- image upload
-
(and 1 more)
Tagged with:
-
Not exactly sure about the structure but you could try this: If you have /article/ /article/page1 /article/page2 /article/page3 Code on article page $root = $page; echo $nav->render(null, $page, $root); // $nav being instance of the module And on the child pages $root = $page->parent; echo $nav->render(null, $page, $root); $page being the current page and $root is from where it starts generating navigation. Yu could also use the various options available to make adjustments, if not needed you can set it to "null" as in the example.
-
Create Pages (with File-Upload Field) via API
Soma replied to MatthewSchenker's topic in API & Templates
Ok I copied your code over and starting taking closer look and test. There was so many faults and things to change, I can't name them all. First off, I changed the input submit and changed to if($input->post->submit){..., since contactname in the form isn't required and just personal preference and a good practice. I made sure debug mode in true in /site/config.php. First submit, BANG!!! error: Fatal error: Exception: Can't save page 0: /about/: It has an empty 'name' field (in /Applications/XAMPP/xamppfiles/htdocs/pwprofile/wire/core/Pages.php line 514) #0 [internal function]: Pages->___save(Object(Page)) #1….. So it can't create and save the page because you don't assign a title nor a "name" to the page before saving. I moved the code around to add those. -- Then there was a wierd line: $contact_photo = $input->post->contact_photo; and later: $np->contact_photo = $contact_photo; // being the file POST Maybe a left off when trying something? -- Then after that, the assignment of the upload to the page image: foreach($files as $filename){ $uploadpage->contact_photo = $upload_path . $filename; } $uploadpage? should be $np -- At the end of when errors found you still have the contest_photo instead of contact_photo. // get the errors foreach($contest_photo->getErrors() as $error) $message .= "<p class='error'>$error</p>"; -- All in all nothing special and nothing wrong with the PW code in there, except the page name left out. But with debug mode on an easy spot. I created a gist with a working version of your code here: https://gist.github.com/somatonic/5207537 (I changed template and parent to my default install but nothing to worry about. I also commented out a bunch not needed to make it work.) Still with the validation of the form fields open to do, currently you only validate the upload and show errors.- 84 replies
-
- 2
-
-
- forms
- image upload
-
(and 1 more)
Tagged with: