-
Posts
1,523 -
Joined
-
Last visited
-
Days Won
21
Everything posted by elabx
-
On form submit, check if field values exist
elabx replied to louisstephens's topic in API & Templates
Could you double check the selector is ok?? I threw in some invented field names in the selector. (sorry to omit that) It seems to me that the $submitted is not throwing a truthsy value (maybe try $submitted->count() so it returns a number which evals to true except for 0 pages found) and it's trying to create a page with the same page name. (John Smith, will crate page john-smith), also for setting the page rather use the $sanitizer->pageName(). Also, reviewing the code, maybe it's more correct to do this: if(isset( $_POST['submit'])){ //Rather only get the first page $submitted = $pages->get("parent=/entries/, (submitter_name={$input->post->name}),(mail={$input->post->mail})"); //Checks for page id, if not it's NullPage object if($submitted->id){ //Code from before }else { $session->redirect("?alert=existing-submission"); } }else { $session->redirect("?alert=form-failure"); } Hope i didn't make this more confusing haha -
virtual url function within ready.php - possible?
elabx replied to Federico's topic in Module/Plugin Development
Here the url should be add-new-recordal, so it gets read by the process module: $wire->addHookAfter("ProcessPageLister::execute", function($event) { if(wire('page')->id === 1413) { // the particular Lister instance page id $out = $event->return; $out .= ''; $btn = wire('modules')->get("InputfieldButton"); $btn->attr('data-href', "./add-new-recordal/"); $btn->addClass("pw-modal"); if(!$this->config->ajax) $out .= $btn->render(); $event->return = $out; } } I have done this in init.php but my wild guess is it should work on ready.php too: $wire->addHook("ProcessPageLister::executeAddNewRecordal", function($event) { // // Create new page and redirect to its edit section $p = new Page(); $p->template = '02_template'; $p->parent_id = 1040; $p->name = 'recordal_' . $pageRecordalsMicrotime; $p->title = 'Recordal_' . $pageRecordalsMicrotime; $p->created_users_id = $this->user->id; $p->of(false); $p->save(); $this->session->redirect(wire('config')->urls->admin."page/edit/?id={$p->id}&modal=1"); } From what I can see, the creation of the page and redirect is already performed in an iframe modal, so it will all happen in the iframe opened with the button you are rendering. Or maybe I'm missing a point here -
On form submit, check if field values exist
elabx replied to louisstephens's topic in API & Templates
if(isset( $_POST['submit'])){ $submitted = $pages->find("parent=/entries/, (submitter_name={$input->post->name}),(mail={$input->post->mail})"); if($submitted){ $u = new Page(); $u->template = "entries"; $u->parent = $pages->get("/entries/"); $u->name = $sanitizer->text($post_name); $u->title = $sanitizer->text($upper_name); $u->save(); $u->setOutputFormatting(false); $session->redirect("?alert=form-success"); }else { $session->redirect("?alert=existing-submission"); } }else { $session->redirect("?alert=form-failure"); } This check is first_name OR mail exists already (and checks for exact value! maybe for name you want: name%=$input->post->name). -
Writing options (from page) to new JS file
elabx replied to louisstephens's topic in API & Templates
What about serving the data in an endpoint? Like, not actually write it to a file but have a json response in an endpoint and asynchronously request for that and have your scripts just respond to that. -
Specific role unable to edit images within a RepeaterMatrix
elabx replied to a-ok's topic in General Support
Maybe it's a permission issue in the repeater matrix template used by the repeater matrix field?? Though makes me wonder why it works on Text type because that one uses the same template as the other types. -
Ajax - Send raw template only, without _main.php
elabx replied to Jim Bailie's topic in General Support
You can check for AJAX calls with: $config->ajax Sets to true if request is async. -
Yes!! It all worked perfectly, thanks!! Thought it was taken for granted lol sorry, this is the working code: $wire->addHookBefore("TemplateFile::render", function($event){ $templateFile = $event->object; if($templateFile->page->template == "repeater_content"){ $customFileName = $this->config->paths->templates . "fields/content/{$templateFile->page->type}.custom.php"; if(is_readable($customFileName)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } elseif($templateFile->page->template == "home" || $templateFile->page->template == "basic-content" ){ $customFileName = $this->config->paths->templates . "{$templateFile->page->template}.custom.php"; if(is_readable($customFileName)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } }); I have some hardcoded if statements because I don't want to be checking for EVERY template, but this works nice for repeater matrix (which uses TemplateFile to render the matrix types) and any other template. Also my first snippet was misleading because I didn't want to do a user check, so I removed that too.
-
Maybe that page also has a contact-form template assigned? If you do a $pages->get() it will only return the first page matching your selector , so if you have multiple pages with template "contact-form", it might not return the one you think of, but the first one PW encounters.
-
Why don't you have a text field in the category page you just created? After created, you can click the title (if using ASM Select for example) to open the page and add more content.
-
One issue is I am not using delayed output but rendering normally through each template/file. Another issue is that I am using also repeater matrix heavily and to keep things organized I also decided to declare the field rendering in each "matrix type" file, so I also wanted to had "alt templates" for this repeater matrix fields rendering.
-
Was just driving back when I thought: Why the heck am I just not checking if the file exists, though I didn't know about is_readable Thanks @kongondo, @Robin S !
-
Hi, I've gone a different way to achieve kind of "auto swap" of template files through hooking TemplateFile, because I wanted to swap template files if a template file with some naming convention exists (eg. home.custom.php replaces home.php) I'd like to ask for some opinions about the performance of this hook and if it makes a sensible approach because it feels a way too much to check for files on disk on every template render: $wire->addHookBefore("TemplateFile::render", function($event){ if($this->user->name == "admin"){ $templateFile = $event->object; if($templateFile->page->template == "repeater_content"){ $existingFiles = $this->files->find($this->config->paths->templates . "fields/content/"); $customFileName = $this->config->paths->templates . "fields/content/{$templateFile->page->type}.custom.php"; if(in_array($customFileName, $existingFiles)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } elseif($templateFile->page->template == "home" || $templateFile->page->template == "basic-content" ){ $existingFiles = $this->files->find($this->config->paths->templates); $customFileName = $this->config->paths->templates . "{$templateFile->page->template}.custom.php"; if(in_array($customFileName, $existingFiles)){ $templateFile->setFilename($customFileName); $event->return = $templateFile; } } } });
-
Why is this mandatory? Does it have to do with template configuration of trailing slashes?? Can this be altered to don't matter in a global way??
-
EDIT: Created topic insted of post.
-
This works?? strtolower($page->options_field->title);
- 4 replies
-
- 1
-
-
- select
- select options
-
(and 1 more)
Tagged with:
-
Doing this myself right now in a project, and very weird what's happening to you because I'm also using the table field inside a RepeatrMatrix and I'm not having any issues with adding rows.
-
Don't think this is possible because Table field uses it's own schema and adds a database column per table column, so changing it in the field would change it to all fields it is instantiated. The quickest idea I have to hack around this is to use RuntimeMarkup field and render your custom inputfield using jQuery datatables or something simliar and save it's data in a hidden text field).
-
@theo Maybe I jumped ahead to help too fast, haha, ¡De nada!
-
Every CKEditor field has a configuration field Custom Editor CSS File (regular mode), by default it is: /site/modules/InputfieldCKEditor/contents.css If you set this option in all your CKEditor fields, with the same path, they will share that css file. https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldCKEditor/README.md#custom-editor-css-file
-
You don't have to write a different file for different field, you cant point the all to the same file. Though you do have to configure each one.
-
Does anyone know if this works with Multiplier fields?
-
I think your are outputing things wrong I see this line: <?php foreach($pages->find("parent=1034") as $item) { echo "<li><a href='index.htm#' data-filter='.{$item->select->category}'>$item->title</a></li>"; } ?> </li> You say the category field is named category? what is that select field you are accessing? I would have expected the code to be like this: <?php foreach($pages->find("parent=1034") as $item) { echo "<li><a href='index.htm#' data-filter='.{$item->title}'>$item->title</a></li>"; } ?> </li> This should output the category title. And on the actual portolio items: <div class="portfolio-item {$item->category->title}<?php echo $single->category->title ?> ">
-
Can I write a better Foreach loop to have different output?
elabx replied to Marco Ro's topic in General Support
Just in case you haven't crossed it: -
I think you have to call save on the field object, not the global $fields. EDIT: what about: $page->set("hiden_field", $value); Because I think you are trying to save the actual field (in the whole PW context), not the field that actually belongs to the page. This would set the field value so it get's saved after the hook.