Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. I've checked out the module source and it doesn't seem to have a customizable `from` address field, so WireMail defaults to admin email. public function ___send() { $from = $this->from; if(!strlen($from)) $from = $this->wire('config')->adminEmail; if(!strlen($from)) $from = 'processwire@' . $this->wire('config')->httpHost; Add this line to site/config.php $config->adminEmail = 'my@email.com'; If you want to change the admin email for just LoginRegister.module, than put the line above where you execute the module. $config->adminEmail = 'my@email.com'; $modules->LoginRegister->execute();
  2. Without touching rewrites or anything: <?php namespace ProcessWire; if ($input->url === '/ads.txt') { $file = $config->paths->templates . 'ads.txt'; if (file_exists($file)) { readfile($file); exit; } } Put this in site/init.php (create if it doesn't exists) If you want to force download, use this one instead if ($input->url === '/ads.txt') { $file = $config->paths->templates . 'ads.txt'; if (file_exists($file)) $files->send($file); }
  3. Yeah, it often takes me multiple tries to get date arithmetics right.
  4. Why not tweak your renderCarousel() function to accept both type of arrays (regular & Pageimages)? Pageimages class is tightly bound to Page class, and not really fit for use in isolation, but you can use any kind of array to do your work. <?php namespace ProcessWire; function renderCarousel($images) { if ($images instanceof WireArray) { // like when $images = $page->images $images = $images->getArray(); // turn into regular arrays } if (!reset($images) instanceof Pageimage) { throw new WireException('$images must be an array of images'); } $out = ""; foreach ($images as $img) { $out .= "<img src='$img->url' alt='$img->description'/>"; } $out = "<div class='carousel'>$out</div>"; return $out; } $images = []; foreach ($carouselPages as $cp) array_merge($images, $cp->images->getArray()); // OR $images = new WireArray(); foreach ($carouselPages as $cp) $images->import($cp->images); echo renderCarousel($images);
  5. FYI: for regular CKEditor fields, there's @Robin S's plugin that lets you add hanna codes quickly https://modules.processwire.com/modules/hanna-code-dialog/
  6. Well, for me it's much faster than VSCode. Admittedly, it starts off a bit slow but after indexing is complete (~5-6 seconds), you shouldn't have any noticeable delays. I can work on multiple projects simultaneously without any lag (on XPS 13 2016, i5 6200U, 8GB RAM, EVO 850 500GB SSD). It performs code analysis and syntax highlighting lazily so having many files open wouldn't affect the performance that much. But having said that, you can disable language injections or enable battery saving mode to disable most power hungry features. But many of these features are what makes PHPStorm great, so don't cripple it down to a regular editor. https://stackoverflow.com/questions/23842924/phpstorm-7-very-slow-and-sluggish-on-netbook-optimize-ide-for-responsiveness Also, it seems mostly mac users are experiencing this problem
  7. LazyCron hooks fire after PW finishes serving the request, so logging inside the hook will not work. Try setting random values to see if changes anything. wire()->addHookAfter('LazyCron::every30Seconds', function (HookEvent $e) { $test = $e->pages->get(1); $test->setAndSave([ 'footerhide' => mt_rand(0, 1), 'meta_desc' => '123' . time() ]); }); If that doesnt work, try deleting site/assets/cache/LazyCron.cache
  8. You named the hanna code as `test`, it should have been `include` instead. (or use [[test file=test]])
  9. Install LazyCron (core module) and add a hook for a certain time period, say LazyCron::everyHour. Something like this should work: wire()->addHookAfter('LazyCron::everyHour', function (HookEvent $e) { $closables = $e->pages->find('closed=0, enddate>now'); foreach ($closables as $p) $p->setAndSave('closed', 1); $openables = $e->pages->find('closed=1, startdate>now, enddate<now'); foreach ($openables as $p) $p->setAndSave('closed', 0); });
  10. Ok, this was a very weird problem. It turns out that when submitting a form with JS, value of the submit button isn't posted with the form, that's why if ($input->post->submitForm) wasn't working as it would normally. We've solved the problem by checking for another field, `stripeToken`, to ensure that the form has been posted properly before processing the credit card. https://stackoverflow.com/questions/1709301/javascript-submit-does-not-include-submit-button-value Another way to solve this problem would be listening to submit button click instead of form submit, then preventing default action, validating the form with Stripe, and actually triggering click on the button.
  11. Here's the simplified version of your JS. One thing you should look out for is that inside your form submit handler, you were preventing default submit action, but then submitting again without removing the handler, which caused the same routine to run repeatedly (submit? can't -> validate -> submit -> can't ,,, repeat). When the form validates and you're ready to submit, remove the handler (that prevents the default action), so that the form can submit properly. // Stripe API var stripe = Stripe('pk_test_*****************'); var elements = stripe.elements(); // DOM Elements var form = document.getElementById('payment-form'); var displayError = document.getElementById('card-errors'); // Card style var style = { base: { fontSize: '16px', lineHeight: '24px' } }; // Create an instance of the card Element // Add an instance of the card Element into the `card-element` <div> var card = elements.create('card', {style: style}); card.mount('#card-number'); card.addEventListener('change', function (event) { if (event.error) showError(event.error.message); else showError(); // remove previous error }); form.addEventListener('submit', handleSubmit); function handleSubmit(event) { event.preventDefault(); stripe.createToken(card).then(function (result) { if (result.error) { return showError(result.error.message); } // remove previous errors showError(); // Send the token to your server injectToken(result.token.id); // prevent infinite loop form.removeEventListener('submit', handleSubmit); // send the form form.submit(); }); } function injectToken(tokenId) { // Insert the token ID into the form so it gets submitted to the server var tokenInput = document.createElement('input'); tokenInput.type = 'hidden'; tokenInput.name = 'stripeToken'; tokenInput.value = tokenId; form.appendChild(tokenInput); } function showError(errorMessage) { // if error is not given, remove previous error errorMessage = errorMessage || ''; displayError.textContent = errorMessage; }
  12. 1. You have two forms nested inside each other. 2. Here's a revised and simplified version: <?php namespace ProcessWire; // create a new form field (also field wrapper) /** @var $form InputfieldForm */ $form = $modules->InputfieldForm; $form->action = "./"; $form->attr("id+name", 'payment-form'); $form->addClass('pusher'); // $form->method = "post"; // default value // add a single field quickly $form->add([ 'type' => 'text', // type is Inputfield<Type> without `Inputfield` 'id+name' => 'name', 'placeholder' => 'Full Name', 'required' => 1, ]); // add multiple fields quickly $form->importArray([ [ 'type' => 'email', 'id+name' => 'email', 'placeholder' => 'Email', 'required' => 1, ], [ 'type' => 'submit', 'id+name' => 'submitForm', 'class' => 'cta white', 'value' => 'Submit Form', // apparently value becomes the button label ], [ 'type' => 'markup', // add custom markup 'value' => '<div id="card-number"></div> <div id="card-errors"></div>' ] ]); // CSRF token field is added by default // Process input if ($input->post->submitForm) { $form->processInput($input->post); if (!count($form->getErrors())) { // process credit card } else { // form has errors, append errors to the form $errors = join('<br>', $form->getErrors()); $form->add([ 'type' => 'markup', 'value' => '<div id="form-errors">$errors</div>' ]); echo $form->render(); } } else { // not posted, show the form echo $form->render(); }
  13. if($input->post->$fieldName) works when there's a field named $fieldName inside the form and its `value` attribute evaluates to a truthy value. So when you change id+name of the`submit` button to `submitForm`, for instance, if ($input->post->submitForm) will work too.
  14. Add hanna code to field's textformatters. Setup > Fields > <fieldname> > Details > Textformatters
  15. https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/#processwire-3.0.5-introduces-field-rendering-with-template-files
  16. @bernhard Here's a preview of some features I use frequently: Variable hinting for API variables for intellisense (when not using API functions, such as page() instead of $page) Ctrl + Q for instant documentation Ctrl + Left Click for instant jump to source. Error hinting Refactoring and reformatting Proper step by step debugging using XDebug Stack trace, scope and global variables, console Variable watchers
  17. So many goodies hidden in the core. Find a proper IDE that lets you navigate around classes easily (PhpStorm, free for students, yay!), and you're pretty much set.
  18. When your requirements exceed what native modules can offer, then, yes you need to implement an Inputfield too. Just use an inputfieldtextarea and show a json of your field data until you start developing your specialized Inputfield.
  19. Change this // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","SUBMIT"); $submit->attr("id+name","submit"); $submit->attr("class","cta white"); $form->append($submit); if($input->post->submit) { into // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","1"); // any nonempty value would work! $submit->attr("id+name","submitForm"); // change `name` attribute to something else to prevent name clash with form.submit $submit->attr("class","cta white"); $form->append($submit); if($input->post->submitForm) {
  20. Unfortunately, it's not the case with my setup. To make sure there aren't any broken images I cleared all CKEditor and image fields, yet the issue persists.
  21. Here's a sample Hanna code that you can use in text fields as [[include file=test]] where `test` is a php file at templates/includes/test.php. <?php namespace ProcessWire; // test.php echo 'hello'; ?> <p>regular html</p> Hanna Code definition is just these lines: <?php $file = "{$config->paths->templates}includes/{$file}.php"; if (file_exists($file)) include $file; Or use this to quickly import into your setup !HannaCode:include:eyJuYW1lIjoiaW5jbHVkZSIsInR5cGUiOiIyIiwiY29kZSI6Ijw/cGhwXG5cbiRmaWxlID0gXCJ7JGNvbmZpZy0+cGF0aHMtPnRlbXBsYXRlc31pbmNsdWRlc1wveyRpbmNsdWRlfS5waHBcIjtcbmlmICghZmlsZV9leGlzdHMoJGZpbGUpKSByZXR1cm47XG5cbmluY2x1ZGUgJGZpbGU7In0=/!HannaCode
  22. It works as long as Hanna Code is added to the field's textformatters.
  23. CKEditor fields are regular HTML strings, they're not evaluated as PHP. Even then, whatever you write in the field is encoded, so < and > for example will turn into &lt; and &gt; HTML escaped variants. Your problem can be solved easily with Hanna Code
×
×
  • Create New...