Jump to content

louisstephens

Members
  • Content Count

    469
  • Joined

  • Last visited

Everything posted by louisstephens

  1. Thanks again @BitPoet, I moved everything out into a new template so I could just test out the page reference field, and for some reason this is still blowing up in my face. I dont get the error like before, but it doesnt seem like anything is working. I simplified my php to: $rawTags = $input->post->tags; $tags = array_map( function($tag) use($sanitizer) { return $sanitizer->text($tag); }, is_array($rawTags) ? $rawTags : [$rawTags] ); $p = $pages->get(1092); $p->of(false); foreach($tags as $tag) { $p->tags->add($tag); bdump($tag); } $p->save(); The bdump shows that $tag = "2018,2019" (which is what I selected from the options field on the frontend", but it does not seem like it is actually adding anything to the field in the backend. 😓
  2. Thanks Bitpoet. I gave it a shot and I am getting: #0 /MAMP/htdocs/development/wire/core/Selectors.php(460): ProcessWire\Selectors->create('hello', '', '') #1 /MAMP/htdocs/development/wire/core/Selectors.php(142): ProcessWire\Selectors->extractString('the-4th-of-july') #2 /MAMP/htdocs/development/wire/core/Selectors.php(128): ProcessWire\Selectors->setSelectorString('hello,the-4th-o...') #3 /MAMP/htdocs/development/wire/core/PagesLoader.php(221): ProcessWire\Selectors->init('hello,the-4th-o...') #4 /MAMP/htdocs/development/wire/core/Pages.php(246): ProcessWire\PagesLoader->find('hello,the-4th-o...', Array) #5 /MAMP/htdocs/development/wire/core/Wire.php(386): ProcessWire\Pages->___find('hello,the-4th-o...', Array) #6 /MAMP/htdocs/development/wire/core/WireHooks.php(733): ProcessWire\Wire->_callMethod('___find', Array) #7 /MAMP/htdocs/development/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'find', Array) #8 /MAMP/htdocs/development/wire/core/PagesLoader.php(430): ProcessWire\Wire->__call('find', Array) #9 /MAMP/htdocs/development/wire/core/Pages.php(390): ProcessWire\PagesLoader->get('hello,the-4th-o...', Array) #10 /MAMP/htdocs/development/wire/modules/Fieldtype/FieldtypePage.module(700): ProcessWire\Pages->get('hello,the-4th-o...') #11 /MAMP/htdocs/development/wire/modules/Fieldtype/FieldtypePage.module(563): ProcessWire\FieldtypePage->sanitizeValuePageArray(Object(ProcessWire\Page), Object(ProcessWire\Field), Array) #12 /MAMP/htdocs/development/wire/core/Page.php(1072): ProcessWire\FieldtypePage->sanitizeValue(Object(ProcessWire\Page), Object(ProcessWire\Field), Array) #13 /MAMP/htdocs/development/wire/core/Page.php(932): ProcessWire\Page->setFieldValue('tags', Array, true) #14 /MAMP/htdocs/development/wire/core/Page.php(1825): ProcessWire\Page->set('tags', Array) #15 /MAMP/htdocs/development/site/templates/ajax.php(64): ProcessWire\Page->__set('tags', Array) #16 /MAMP/htdocs/development/wire/core/TemplateFile.php(287): require('/Volumes/ArtDep...') #17 /MAMP/htdocs/development/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #18 /MAMP/htdocs/development/wire/core/WireHooks.php(733): ProcessWire\Wire->_callMethod('___render', Array) #19 /MAMP/htdocs/development/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #20 /MAMP/htdocs/development/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array) #21 /MAMP/htdocs/development/wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent)) #22 /MAMP/htdocs/development/wire/core/WireHooks.php(733): ProcessWire\Wire->_callMethod('___renderPage', Array) #23 /MAMP/htdocs/development/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageRender), 'renderPage', Array) #24 /MAMP/htdocs/development/wire/core/WireHooks.php(834): ProcessWire\Wire->__call('renderPage', Array) #25 /MAMP/htdocs/development/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Page), 'render', Array) #26 /MAMP/htdocs/development/wire/modules/Process/ProcessPageView.module(206): ProcessWire\Wire->__call('render', Array) #27 /MAMP/htdocs/development/wire/core/Wire.php(383): ProcessWire\ProcessPageView->___execute(true) #28 /MAMP/htdocs/development/wire/core/WireHooks.php(733): ProcessWire\Wire->_callMethod('___execute', Array) #29 /MAMP/htdocs/development/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'execute', Array) #30 /MAMP/htdocs/development/index.php(55): ProcessWire\Wire->__call('execute', Array) #31 {main} I guess I shouldnt be tryping to still pass $tags the same way I was with $p->tags = $tags? Sorry, I have never used array_map before so I wasnt sure of the desired output etc. I do appreciate the help
  3. Going through my long quest to get better with ajax and utilizing the api, I have hit yet another roadblock. I currently have a form with an image field (thanks to flydev for getting that sorted), "title" text input, and a select field set to multiple. In my ajax call, I added in: tags = $("#select-tags").val(); form_data.append('tags', tags); $.ajax({ type: 'POST', data: form_data, contentType: false, processData: false, url: '/ajax/upload-preview/', success: function(data) { console.log("Woo"); }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); } }); And in the ajax template: $tags = $sanitizer->text($_POST['tags']); $image = $sanitizer->text($_POST['image']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->tags = $tags; $p->save(); If I select a "tag" from the select input and submit, it does indeed add it to the Page Reference field in the backend. However, this does not work with an array being passed to it of multiple options. So it does appear that my ajax call is trying to submit multiple options, but I am really just unsure how to get these two added in. I saw in other forums posts of add($page) and even add(array()). Do I need to handle this js array differently or do I need to foreach through the $tags to add it like: foreach($tags as $tag) { $p->tags->add($tag); $p->save(); } I tried this approach, but apparently I am still missing something. Edit: I was doing some tweaking, and I know I can split the js array out like: for (i = 0, len = tags.length; i < len; i++) { console.log(tags[i]); } However, I am not sure then how to handle the POST in php if I were to split it out.
  4. You have officially saved my sanity flydev! Thank you so much. I had stared at/fiddled with this all day yesterday to no avail.
  5. I have been messing around with creating pages from ajax requests, and it has gone swimmingly thus far. However, I am really struggling with creating a page and saving an image via ajax. The form: <form action="./" role="form" method="post" enctype="multipart/form-data"> <div> <input type="text" id="preview" name="preview" placeholder="Image Title"> </div> <div> <input type="file" id="preview-name" name="preview-name"> </div> <div> <select id="select-tags" name="select-tags"> <?php $tags = $pages->find("template=tag"); ?> <option value="">Select Your Tags</option> <?php foreach ($tags as $tag) : ?> <option value="<?= $tag->name; ?>"><?= $tag->name; ?></option> <?php endforeach; ?> </select> </div> <div> <button type="button" id="submit-preview" name="submit" class="">Upload Images</button> </div> </form> The ajax in my home template: $('#submit-preview').click(function(e) { e.preventDefault(); title = $("#preview").val(); image = $("input[name=preview-name]"); console.log(title); console.log(image); data = { title: title, image: image //not sure if this is actually needed }; $.ajax({ type: 'POST', data: data, url: '/development/upload-preview/', success: function(data) { console.log("Woo"); }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); } }); }); And finally in my ajax template: $imagePath = $config->paths->assets . "files/pdfs/"; //was from an older iteration $title = $sanitizer->text($_POST['title']); $image = $sanitizer->text($_POST['image']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->save(); $p->setOutputFormatting(false); $u = new WireUpload('preview_image'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setDestinationPath($p->preview_image->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf')); foreach($u->execute() as $filename) { $p->preview_image->add($filename); } $p->save(); I can complete the file upload but just using a simple post to the same page and it it works well, but I was really trying to work out the ajax on this so I could utilize some modals for success on creation (and to keep my templates a little cleaner). When I do run the code I have, a new/blank folder is created under assets, and a new page is created with the correct title entered. However, no image is being processed. I do get a 200 status in my console. I have searched google for help, but everything seems to be slightly off from my needs. If anyone could help point me in the right direction I would greatly appreciate it.
  6. This might be a completely dumb question, but I cant seem to wrap my head around it. I have a page reference field that allows users to select "Tags". In the front end I would like to use the titles as class names for a single item. ie: <?php $previews = $pages->find("template=preview"); ?> <?php foreach($previews as $preview): ?> <div class="tagOne TagTwo tagThree"> <!-- use another foreach to output--> <img src="<?=$preview->preview_image->url; ?>" /> </div> <?php endforeach; ?> I am little stumped as I know I need a foreach loop to produce each tag title, but how do I insert them all into one corresponding div class with spaces? Whelp, that was the easiest thing, but my brain just didnt "get it". Just put the foreach in the "class" inside of the overall foreach. Ugh 😓
  7. So I am using ajax to upload an image, but I am getting the error "Method WireUpload:: save does not exist or is not callable". I am not quite sure how to go about fixing this (at the moment). elseif($config->ajax && $input->urlSegment1 == "upload-preview") { $u = $config->paths->assets . "files/pdfs/"; $title = $sanitizer->text($_POST['title']); $p = new Page(); $p->template = "preview"; $p->parent = $pages->get("/previews/"); $p->name = $title; $p->title = $title; $p->save(); $p->setOutputFormatting(false); $u = new WireUpload('preview_image'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setDestinationPath($p->preview_image->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf')); foreach($u->execute() as $filename) { $p->preview_image->add($filename); } $u->save(); } I compared my code to something I did previously (though previously I just posted to the current template file, not through ajax) which works, but this doesnt seem to be working. I have the _init.php file prepending as well. Does anyone have any ideas of what might be happening?
  8. It really depends on what you have named your fields. I believe by "default" (on the basic-page template) they are title, headline, summary, body, sidebar, and images. <?php echo $page->title; ?> <?php echo $page->headline; ?> <?php echo $page->summary; ?> <?php echo $page->body; ?> <?php echo $page->sidebar; ?> However, your templates could/most likely be vastly different than what anyone else has.
  9. I believe it is as simple as doing: <?php $p = $pages->get('template=your-template, n1|n2=10'); echo $p->id; ?>
  10. Could you show an example of your template file where you are trying to output the header image? Also, is you "header" field set to single image or multiple images? If multiple, the example I gave will not work.
  11. Do you mean in your template file? If so, you can do: <img src="<?php echo $page->header->url; ?>" alt="<?php echo $page->header->description; ?>" /> This will get the url of the header image and allow you to out put the image for the page.
  12. The end result (hopefully) to be able to just include a script tag on a project like: <script src="https://domain.com/launch?first_name=jim&occupation=builder"></script> and somehow have access to the field data for the particular job. I could then just append in the data to where I want on the new project. I was kinda hoping to have processwire really taking care of the posting/get of the data. In the long run, pw could be used to have many other pages not related to people, and I could simply change out the parameters to access the data in new/different projects.
  13. So I reread my first draft, and it made absolutely no sense (I deleted it to hopefully better explain myself). I am trying to make a system (that to me is a bit complicated) utilizing jquery and processwire together. My whole goal is to put a url like https://domain.com/launch?first_name=jim&occupation=builder in a script tag on another site(just a localhost .php page) to then pull out the data for that person and append to divs etc. Basically, the initial script tag would point to "launch" which has a content-type of "application/javascript". Using jquery, I would pull out the persons name and occupation and then make a specific ajax get request to "domain.com/api" (in json format) for a look up of the person. Essentially then I could pull that particular person's information from the json data, and do with it how I please in the "launch" page. In processwire, I have a page structure like: People -Jim Bob (template: person ) --Occupations (template: basic-page) ---Builder (template: occupation) ---Greeter (template: occupation) It is really just a bunch of people with their occupations and a few fields to the occupation template. With the "api" (template: api) url, I was hoping to return all the data (of people) in json format like: Example Format: { "id": 1, "title": "Jim Bob", "occupations": { "builder": { "id": 44, "title": "Builder", "years_worked": 1, "etc": "ect", }, "Greeter": { "id": 44, "title": "Greeter", "years_worked": 1, "etc": "ect", }, } } Where I get lost is really outputting the page names and nesting in the occupations into json. I have used Pages2JSON before, but I was a bit lost on how to implement what i was thinking. I have access to all the local host files, but I was hoping to kind of build out a "system" where I could place the script tag/parameters in any project, and be able to interact with the data without doing an ajax call on the actual site. In a way, this would keep processwire handling all the data and requests, and my other "projects" just with a simple script tag. This might all be way too much/over complicated, but I couldn't quite wrap my head around how to achieve it.
  14. So I have a template called "development" where I am testing out a few ideas etc set up on a local mamp server. I also have a page called "ajax" using a template called ajax. From my development template, I am posting a form using ajax and all is working quite well: $('.test').click(function(event) { event.preventDefault(); redirectUrl = $(this).data('redirect'); var data = { firstName: $("#firstname").val(), lastName: $("#lastname").val(), email: $("#email").val(), phone: $("#phone").val(), redirectUrl: redirectUrl }; $.ajax({ type: "POST", url: "localhost:8888/sandbox/ajax/form/", data: data, success: function() { console.log(this.data); top.window.location = redirectUrl; }, failure: function() { console.log(this.data); } }); And in my ajax template: if($input->urlSegment == 'form'){ if ($_POST) { //handle the post } } The redirectUrl is a data attribute I added in to the button (that launches the form in a modal) that pulls in from a field in processwire. Everything works just fine locally, but when I export everything to a live site it fails. It will work 1 time and redirect, but if you go back to resubmit, it submits the data but won't redirect. Can anyone see any glaring issue here, or have a better way around this? ------------------------------ So, it turns out the request to /ajax/form/ was being canceled. It still handled the POST request, but never sent back a 200 to show "success". Adding in return false; at the end of my .onclick solved the issue. It is strange though as I have never had this issue before.
  15. Just curious, is "daurl" a field you have defined in processwire? If not, i think you might need to use $page->url for the actual url of the page
  16. When I go to the link provided, I currently see a "sample swap feedback" image and sidebar without any errors. What is supposed to be displaying?
  17. Yet another great example of the power of processwire! I was curious, since you have one template file, how do you handle all the "blocks", though conditional statements? I really like this approach and actually was working on something similar, but tbh, I kinda got lost in all of my conditional logic.
  18. 1. I would assume that the Robots field is where you could insert "noIndex or noFollow". This tells web crawlers to basically ignore the page from crawling. 3. The canonical link tag ie : <link rel="canonical" href="path_to_page" /> tells search engines where the original version of the content is located. This comes in handy when you are utilizing AMP, so google can differentiate the desktop version (canonical) and the accelerated mobile page. As for number 2, it looks like you can input schema tags . However, do you know if these fields were created from scratch, or are these generated by a certain module like SEOmaestro?
  19. Hey Mafuz, did you mean to post your question regarding django in a forum for ProcessWire? Stackoverflow might be the best forum for you to get your question answered.
  20. I have used ProcessWire as more of a framework numerous times last year. I will say, that sometimes recreating some of the backend functionality in the frontend was a bit of the headache (solely based on things like repeaters etc). Overall, it was very easy to get a front end going and using ajax to post/pull from the backend. I did use the Pages2Json to deliver the json with made the requests a bit easier for me. I am sure there are many more people here that have made bigger scale web apps though, and they might be able to give a bit more in depth response.
  21. I have not implemented this yet for myself, but I did stumble across this in my bookmarks. It looks promising with srcset etc.
  22. Well darn, I set $config->advanced to true, and nothing seems to be changing for me on the field settings. Is there something else I need to change out? That was completely my fault. I changed a config in the wrong folder without thinking. Thanks adrian, that solved the issue.
  23. Thanks adrian! I went to the advanced tab, but perhaps I am missing something. The only options present are: tags icon autojoin global I then went through tracy to delete it, but I am still met with the samed flagPermanent error message. I will continue to poke around and see what might be causing it.
  24. Hey iipa, Just curious, how are you calling the file in your template? I have used the following without issue in the past. <link rel="icon" type="image/png" href="<?php echo $config->urls->templates?>/favicon.png" />
×
×
  • Create New...