Jump to content

Juergen

Members
  • Posts

    1,221
  • Joined

  • Last visited

  • Days Won

    10

Community Answers

  1. Juergen's post in How to check if username and password match in PW? was marked as the answer   
    Ok I was a little bit too fast with my first entry.
    Replace
    if ($u->id && $u->pass && $u->pass === $pass) { with
    if($u->id && $u->pass->matches($pass)){ and it works
  2. Juergen's post in Anyone done Ajax login with bootstrap.io form validation? was marked as the answer   
    Ok I have figured it out. But one problem remains: User is logged in automatically without clicking the submit button. So if the username and password are entered correctly the user is logged in. Is there a way to prevent this.
    Here is the working code for others who are interested in:
    Js validation code:
    <script> $(document).ready(function() { $('#mainlogin-form').formValidation({ framework: 'bootstrap', icon: { valid: 'fa fa-check', invalid: 'fa fa-remove', validating: 'fa fa-refresh fa-spin' }, fields: { user: { verbose: false, validators: { notEmpty: { message: '<?php echo _t('Username missing! Please enter your username', 'Login');?>' }, different: { field: 'pass', message: 'The username and password cannot be the same as each other' }, } }, pass: { verbose: false, validators: { notEmpty: { message: '<?php echo _t('Password missing! Please enter your password', 'Login');?>' }, different: { field: 'user', message: 'The username and password cannot be the same as each other' }, remote: { url: '<?php echo $ajaxloginurl;?>', data: function(validator) { return { user: $('[name="user"]').val(), pass: $('[name="pass"]').val() }; }, message: 'Dont match' } } } } }); }); </script> Here is the changed code from the json file:
    <?php //check if password and username match $match = true; $username = $input->get['user']; $pass = $input->get['pass']; $u = $users->get($username); //check if log in with temp pass if ($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { // user logging in with tmp_pass, so change it to be their real pass $u->of(false); $u->pass = $u->tmp_pass;//set temp pass value as pass value $u->tmp_pass = '';//delete temp pass value $u->save(); $u->of(true); } //try to login with password and username if ($session->login($username, $pass)) { // login successful $match = true; } else { //password and username dont match $match = false; } // Finally, return a JSON echo json_encode(array( 'valid' => $match, )); ?> This code line is responsible for the automatic login:
    if ($session->login($username, $pass)) {..... Is there  a way to prevent this?
    I have asked a new question to this specific topic: https://processwire.com/talk/topic/13265-how-to-check-if-username-and-password-match-in-pw/?p=119972
    Therefore this topic is solved.
  3. Juergen's post in Is it possible to show a page table only if there are items in it? was marked as the answer   
    This works!!!
    Here is the complete code for others who are interested in:
    //initialize the function in the module public function init(){ $this->addHookAfter("ProcessPageEdit::buildFormContent", $this, "renderpagetable"); } public function rendepagetable($event){  $wrapper = $event->return;  $page = $event->object->getPage();   if(!$wrapper->has('singleeventtable')) return;   $itemnumber = count($page->children);   if ($itemnumber == 0) {     $this->message('There are no items in the page table field');     $wrapper->singleeventtable->collapsed = Inputfield::collapsedHidden;   } else {     $this->message("Number of items:{$itemnumber}");   } } } "singleeventtable" is the name of my page table field - replace it with your own page table field name.
    Special thanks to netcarver and LostKobraKai for helping to find a working solution.
  4. Juergen's post in Strange error on PW 3.06, 3.07 and core Textarea field image settings was marked as the answer   
    Simple solution to this problem: By clicking the X-symbol (delete) on the right side the error message does not appear at the next login.
    Strange! I have tried this some time ago without success.
  5. Juergen's post in Options fieldtype and storage problem was marked as the answer   
    Problem solved:
    The cause of the problem was the wrong order of fields with dependencies in the template. Field B has a dependency of field A, but A was after B. I changed the field order from B, A to A, B and now it works.
  6. Juergen's post in Use lazy cron in child pages which are not reachable directly with a link was marked as the answer   
    I changed the code a little bit. I dont use children in this case and now it works.
    <?php class AddCronJob extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Add Cron jobs for various functions.', 'version' => 100, 'summary' => 'Executing cron job tasks depending on time set', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('LazyCron::every30Seconds', $this, 'ChangeOfferPages'); } public function ChangeOfferPages(HookEvent $e) { $seconds = $e->arguments[0]; $currentdatetime = time(); // Get timestamp for current date $pricelistpages = wire("pages")->find("template=productpricelistitem"); //get the page with the price template foreach ($pricelistpages as $pp) { $pp->setOutputFormatting(false); // without this we can't save the page later on $offerend = $pp->getunformatted(offerend); if ($offerend) { if (($pp->afterofferend == "1") AND ($offerend < $currentdatetime)) { $pp->pricetype = "1"; //set back price type to standard price $pp->offertprice = ""; //delete offerprice $pp->offerstart = ""; //delete offerdate start $pp->offerend = ""; //delete offerdate end $pp->save(); //save the price page } } } } }
  7. Juergen's post in How to add a value of a child page via hook after save to a field of the parent page was marked as the answer   
    Thanks for your help LostKobraKai and Martijn, now the value will be added to the parent page.
    For all others who are interested in this, here is the complete code snippet:
    public function init() { $this->addHookAfter('Pages::saved', $this, 'saved'); } public function saved($event) { $page = $event->arguments[0]; if($page->template == "productpricelistitem"){ //run the hook under this condition - page which will be edited $parent = $page->parent;//get the parent page $parent->offercheck = "5"; //example value to store in the parent page in the field with the name offercheck $parent->save("offercheck"); //save the parent page } } If you use a pagetable field as in my case, dont forget to reload the parent page if you want to see the value in the field.
    Best regards
  8. Juergen's post in Displaying search result with link to parent was marked as the answer   
    Thank you Nicolas and Macrura for your suggestions!!!
    Unfortunately I have forgotten to mention that the child pages are part of a Page table field on the parent page.
    So here is my solution to search the Page table field with its "sub fields" from the child pages and output only the parent page in the search results if a search term was found in one (or more) child page(s).
    This are the fields of the Page table field to search:
    $pricelistfields = "servicepricelist.title|servicepricelist.description"; The Page table field name in my case is "servicepricelist" and I search in the "title" and the "description" field which are part of the child pages.
    The next step is to exclude all the childpages in the search to prevent duplicate content.
    $selector = "$searchfields~=$q, template!='pricelistitem', limit=50"; $matches = $pages->find($selector); I add "template!='pricelistitem'" to the search selector, because the template name of the child pages is "pricelistitem". So I get rid of all matches in the child pages directly. It only shows matches in the parent page.
    Thats all!
  9. Juergen's post in Whitespace at the beginning of the source code leads to problems was marked as the answer   
    Updating to PW 2.6.0 stable solves the problem - the whitespace at the beginning is gone.
  10. Juergen's post in Remove (disable) invalid attributs of tables in CKEditor was marked as the answer   
    This is the solution to remove unwanted table attributes from CKEditor.
    Go to /wire/modules/Inputfield/InputfieldCKEditor/ckeditor-4.4.6/config.js and insert this piece of code into the config.js:
    CKEDITOR.on( 'dialogDefinition', function( ev ) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if (dialogName == 'table') { // Get the advanced tab reference var infoTab2 = dialogDefinition.getContents('advanced'); //Set the default // Remove the 'Advanced' tab completely dialogDefinition.removeContents('advanced'); // Get the properties tab reference var infoTab = dialogDefinition.getContents('info'); // Remove unnecessary bits from this tab infoTab.remove('txtBorder'); infoTab.remove('cmbAlign'); infoTab.remove('txtWidth'); infoTab.remove('txtHeight'); infoTab.remove('txtCellSpace'); infoTab.remove('txtCellPad'); infoTab.remove('txtCaption'); infoTab.remove('txtSummary'); } }); After that you have only a few attributes left. This is the best way to prevent customers from filling out useless table attributes. This works for other plugins (images, links and so on) too.
    A big thanks to Lostkobrakai for pointing me into the right direction.
  11. Juergen's post in Problem with checkbox and redirect was marked as the answer   
    Sorry,
    I dont need to save the checkbox status after redirect, because the redirect only take place if the form has no errors. So all correct data will be submitted via the form and will be stored in the database before the redirect starts. No need to keep the checkbox state alive.
    [CLOSED]
  12. Juergen's post in Single image upload on frontend doesnt work correctly was marked as the answer   
    I found the solution:
    you have to include
    $user->userimage->removeAll(); // wirearray before this line of code
    $user->userimage = $upload_path . $files[0]; This removes the image array in a first step and then loads the new image in the database.
  13. Juergen's post in Userimage and resize doesnt work on frontend with API was marked as the answer   
    I have changed the image settings from "auto" to "single element (null if empty)" and now it works.
    Thanks for your efforts
  14. Juergen's post in Option fieldtype and select status was marked as the answer   
    Yes that was the problem
    (Hint: This code is for multilingual site):
    You have to insert the following code to get the values in different languages:
    if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; } else { $title = 'title'; $value = 'value'; } Then you can start to create the options for the select
    $storedgender = $user->YOUROPTIONFIELDNAME->id; $genderoptionstag = ""; //make select for gender options $genderoptions = $fieldtypes->get('FieldtypeOptions')->getOptions('YOUROPTIONFIELDNAME'); foreach($genderoptions as $option) {   $genderid = $option->id;   $gendervalue = $option->$value;   $gendertitle = $option->$title;         if ($storedgender == $genderid) {       $genderstatus = " selected";       } else {       $genderstatus = "";             }       $genderoptionstag .= "<option$genderstatus value='$genderid'>$gendertitle</option>"; }; //here you can output the option tags wherever you want (in my case in the user frontend form) echo $genderoptionstag;
  15. Juergen's post in Upgrade from 2.5.24 to 2.5.25 broke the site was marked as the answer   
    Thats true but it worked quite well until this update. Anyway!
    My recommendation: Be careful if you use this module with wire version 2.5.25 - it brokes the site in my case
  16. Juergen's post in Unexpected behaviour of field dependency and checkbox field was marked as the answer   
    For all users with the same problem:
    Downloading inputfields.js and the minified version from Github solved the problem. I had slightly different js files in my directory and they have caused the strange behaviour.
    Thanks to all contributors for their efforts to solve the problem.
  17. Juergen's post in Select Options Fieldtype: Possible to output all available options in template? was marked as the answer   
    Issue was fixed by Ryan.
    $options = $fieldtypes->get('FieldtypeOptions')->getOptions('YOURFIELDNAME'); foreach($options as $option) { echo $option->id; echo $option->value; echo $option->title; } This output all your options (id, value or title).
    This piece of code doesnt work multilingual. It only outputs the default language.
    If you have a multilingual site you have to output value and title in the specific language.
    //get value and title in different languages; if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; } else { $title = 'title'; $value = 'value'; } $options = $fieldtypes->get('FieldtypeOptions')->getOptions('YOURFIELDNAME'); foreach($options as $option) { echo $option->id; echo $option->$value; echo $option->$title; }; Hope this is useful for others!
  18. Juergen's post in Repeater field and visibility rule storage problem was marked as the answer   
    Issue already well known (https://github.com/ryancramerdesign/ProcessWire/issues/803#comments) - so thread closed.
  19. Juergen's post in User language always fall back to default after login in frontend was marked as the answer   
    I have traced the problem down. As Soma pointed out the cause is the save command in the login form. I have tested it with phpmyadmin and the database change is after the login as a cause of the $u->save() process.
    Here is the solution for this issue from this discussion: https://github.com/ryancramerdesign/ProcessWire/issues/409
    First of all download the new file from here: https://github.com/ryancramerdesign/ProcessWire/blob/a411e2523f5f14d2354f40a661e41503595a890a/wire/core/Pages.php
    Go to wire/core and find the Pages.php. Replace the code with the code downloaded above
    After this the userlanguage will not change after frontend login. It stays the same in the database.
    Alternatively, as Soma pointed out too, you can update to 2.5 dev-version, but I have not tested it.
    Best regards Jürgen
×
×
  • Create New...