Jump to content

Juergen

Members
  • Posts

    1,421
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Juergen

  1. I have tried it with PW 3.21 and it seems not to work any longer. I always get Error 500.
  2. Hello bernhard, unfortunately the developer makes the latest versions commercial, but there is a version for free on jsdelivr.net
  3. 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
  4. Hello @ all, I want to know how to check if username and password match in PW. I need an if condition to get true or false. Here is the code so far: $match = true; $username = $input->get['user']; $pass = $input->get['pass']; $u = $users->get($username); if ($u->id && $u->pass && $u->pass === $pass) { $match = true; } else { //password and username dont match $match = false; } // Finally, return a JSON echo json_encode(array( 'valid' => $match, )); "user" ist the formfield with the username; "pass" is the formfield with the password. This code should output a json string with valid true or false (for Ajax response). Unfortunately this code doesnt work I get always false. Does anybody know how to check the matching?
  5. 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.
  6. Hello @ all, I am using the following js-framework to validate my frontend forms: http://formvalidation.io/ My goal is to check if username and password match via Ajax, so the customer will see immediately if the entered values are correct or not. For this reason I have included the following js snippet inside the template with the login form. <?php $ajaxlogin = $pages->get("template=jsonlogin"); $ajaxloginurl = $ajaxlogin->httpUrl; ?> <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> This script should send the values of the fields user and pass to the backend (json file). Field username = user, field password = pass. The backend file looks like this: <?php //check if password and username match $match = true; $username = $input->get['user']; $pass = $input->get['pass']; $u = $users->get($username); //check if userid and password/temp password match if (($u->id && ($u->pass == $pass)) OR ($u->id && ($u->tmp_pass == $pass))){ $match = true; } else { $match = false; } // Finally, return a JSON echo json_encode(array( 'valid' => $match, )); ?> It should return true if both values match and false if not. In this case the username check works as standalone, but the combination of username and password match not. I can also not check if the password is in the db as standalone - this is probably a reason that it is not stored as a standard value. So I guess the problem could be in the jsonfile and not in the js file. It would be great if a user also uses this validation framework and can help me out. Here is another link that probably can help: http://stackoverflow.com/questions/27143058/bootstrap-validator-send-all-input-field-values-to-remote-php-file Thanks in advance
  7. Hello @ all, I have problems with the "add to cart button". I have several add to cart buttons on one product page (for various colors of the same product). Each of these product variations is a child template. The parent is the product page. - productpage (parent) - childpage (color blue) - childpage (color green) - childpage (color yellow and so on) Each child template contains price, stockvalue and so on. All children are included with a foreach loop in the parent template. Problem: I have choosen the child template as product template because it contains all the necessary values (price, stockvalue). If I push the add to card button I always get an error 500 because it leads me to the page http://www.*****.at/padloper/add/ which doesn exist. If I choose the parent template as product template, I didnt get the error message, but price and stockvalue are not reachable because they are in the child template. Can anyone tell me the right way in such a scenario? Best regards
  8. Good idea but no effect. Sanitization: public function sanitizeValue(Page $page, Field $field, $value) { $value = str_replace(",",".",$value); if(!$value instanceof ProductData) { $value = $this->getBlankValue($page, $field); } // report any changes to the field values if($value->isChanged('length') || $value->isChanged('weight') || $value->isChanged('needlemin') || $value->isChanged('needlemax')) { $page->trackChange($field->name); } return $value; } DB schema changed to decimal: public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data_length'] = 'DECIMAL(12,1) NOT NULL default 0'; $schema['data_weight'] = 'DECIMAL(12,1) NOT NULL default 0'; $schema['data_needlemin'] = 'DECIMAL(12,1) NOT NULL default 0'; $schema['data_needlemax'] = 'DECIMAL(12,1) NOT NULL default 0'; // key for data will already be added from the parent $schema['keys']['data_weight'] = 'KEY data_weight(data_weight)'; $schema['keys']['data_needlemin'] = 'KEY data_needlemin(data_needlemin)'; $schema['keys']['data_needlemax'] = 'KEY data_volume(data_needlemax)'; return $schema; }
  9. Here are some screenshots from the db and from the admin interface.
  10. Wake up value shows fe. 3,5 instead of 3.5. I have added a comma number manually in the database for testing purposes in the format 3.5. Strange that wake up value use a comma instead of the dot.
  11. The wakup values come with comma and not with a dot. But they are stored manually with a dot in the db.
  12. Yes I have reinstalled the fieldtype. How can I check the wakeup value -> with tracy debugger?
  13. The numbers are entered with a dot and not a comma. I have used the arrows on the right side of the inputfield to increase or decrease the number. It seems that the decimal will be rounded. On the other side, if I enter a decimal directly in the sql table I got a blank output in the field at the admin side. So it outputs and stores only integer.
  14. Hello @ all, I have created a new fieldtype which should be able to store 4 float values. Therefore I have tried to adapt this fieldtype from Soma. http://modules.processwire.com/modules/fieldtype-dimension/ Instead of storing integer values as in Somas fieldtype I want to store float values (fe. 3.5). Here is what it looks like in the admin: Problem: It stores the values only as integer and not as float. This means if I enter fe 2.5 it stores always 2. Here are the 2 files for the fieldtype: 1) FieldtypeProductDate.module <?php /** * ProcessWire ProductData Fieldtype * Field that stores 4 float values for length/weight/minsize/maxsize. * * ProcessWire 2.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class FieldtypeProductData extends Fieldtype { public static function getModuleInfo() { return array( 'title' => __('ProductData Fieldtype', __FILE__), // Module Title 'summary' => __('Field that stores 4 float values for length, height and needle minsize and needle maxsize.', __FILE__), // Module Summary 'version' => 100, 'author' => 'Juergen', 'installs' => 'InputfieldProductData' ); } /** * Format value for output * */ public function ___formatValue(Page $page, Field $field, $value) { return $value; } /** * * Add mapping to different name for use in page selectors * This enables us to use it like "field.length=100, field.weight<=200, field.needlemax>100" */ public function getMatchQuery($query, $table, $subfield, $operator, $value) { if($subfield == 'length') $subfield = 'data_length'; if($subfield == 'weight') $subfield = 'data_weight'; if($subfield == 'needlemin') $subfield = 'data_needlemin'; if($subfield == 'needlemax') $subfield = 'data_needlemax'; return parent::getMatchQuery($query, $table, $subfield, $operator, $value); } /** * get Inputfield for this fieldtype, set config attributes so they can be used in the inputfield * */ public function getInputfield(Page $page, Field $field) { $dim = $this->modules->get('InputfieldProductData'); return $dim; } /** * there's none compatible * */ public function ___getCompatibleFieldtypes(Field $field) { return null; } /** * blank value is an WireData object ProductData * */ public function getBlankValue(Page $page, Field $field) { return new ProductData(); } /** * Any value will get sanitized before setting it to a page object * and before saving the data * * If value not of instance ProductData return empty instance */ public function sanitizeValue(Page $page, Field $field, $value) { if(!$value instanceof ProductData) $value = $this->getBlankValue($page, $field); // report any changes to the field values if($value->isChanged('length') || $value->isChanged('weight') || $value->isChanged('needlemin') || $value->isChanged('needlemax')) { $page->trackChange($field->name); } return $value; } /** * get values converted when fetched from db * */ public function ___wakeupValue(Page $page, Field $field, $value) { // get blank dim $dim = $this->getBlankValue($page, $field); // populate the dim $dim->length = (float) $value['data_length']; $dim->weight = (float) $value['data_weight']; $dim->needlemin = (float) $value['data_needlemin']; $dim->needlemax = (float) $value['data_needlemax']; return $dim; } /** * return converted from object to array for storing in database * */ public function ___sleepValue(Page $page, Field $field, $value) { // throw error if value is not of the right type if(!$value instanceof ProductData) throw new WireException("Expecting an instance of ProductData"); $sleepValue = array( 'data_length' => (float) $value->length, 'data_weight' => (float) $value->weight, 'data_needlemin' => (float) $value->needlemin, 'data_needlemax' => (float) $value->needlemax ); return $sleepValue; } /** * Get the database schema for this field * * @param Field $field In case it's needed for the schema, but usually should not. * @return array */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data_length'] = 'float NOT NULL default 0'; $schema['data_weight'] = 'float NOT NULL default 0'; $schema['data_needlemin'] = 'float NOT NULL default 0'; $schema['data_needlemax'] = 'float NOT NULL default 0'; // key for data will already be added from the parent $schema['keys']['data_weight'] = 'KEY data_weight(data_weight)'; $schema['keys']['data_needlemin'] = 'KEY data_needlemin(data_needlemin)'; $schema['keys']['data_needlemax'] = 'KEY data_volume(data_needlemax)'; return $schema; } /** * Get any inputfields used for configuration of this Fieldtype. * * This is in addition any configuration fields supplied by the parent Inputfield. * * @param Field $field * @return InputfieldWrapper * */ public function ___getConfigInputfields(Field $field) { $inputfields = parent::___getConfigInputfields($field); // nothing yet return $inputfields; } } /** * Helper WireData Class to hold a dimension object * */ class ProductData extends WireData { public function __construct() { $this->set('length', null); $this->set('weight', null); $this->set('needlemin', null); $this->set('needlemax', null); } public function set($key, $value) { if($key == 'length' || $key == 'weight' || $key == 'needlemin' || $key == 'volume') { // if value isn't numeric, don't change the value if already // one set, else set it to 0 and throw an exception so it can be seen on API usage if(!is_float($value) && !is_null($value)) { $value = $this->$key ? $this->$key : 0; throw new WireException("ProductData Object only accepts number values"); } } return parent::set($key, $value); } public function get($key) { return parent::get($key); } } 2) InputfieldProductData.module <?php /** * ProcessWire ProductData Inputfieldtype * ProcessWire 2.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class InputfieldProductData extends Inputfield { public static function getModuleInfo() { return array( 'title' => __('ProductData Inputfield', __FILE__), // Module Title 'summary' => __('Simple dimension input field.', __FILE__), // Module Summary 'version' => 100, 'author' => 'Juergen', 'requires' => array("FieldtypeProductData") ); } /** * Construct the Inputfield, setting defaults for all properties * */ /** * Per the Module interface, init() is called when the system is ready for API usage * */ public function init() { return parent::init(); } /** * Return the completed output of this Inputfield, ready for insertion in an XHTML form * * @return string * */ public function ___render() { $out = ''; $value = $this->attr('value') ? $this->attr('value') : new ProductData(); $label_length = $this->_("Length"); $label_weight = $this->_("Weight"); $label_needlemin = $this->_("Needlesize min"); $label_needlemax = $this->_("Needlesize max"); $out .= "<div class='dimension_col'>"; $out .= "<label>{$label_length}: <input type='number' min='0' style='width:100px' name='{$this->name}_length' id='Inputfield_{$this->name}_length' value='{$value->length}'/> m</label>"; $out .= "</div>"; $out .= "<div class='dimension_col'>"; $out .= "<label>{$label_weight}: <input type='number' min='0' style='width:100px' name='{$this->name}_weight' id='Inputfield_{$this->name}_weight' value='{$value->weight}'/> g</label>"; $out .= "</div>"; $out .= "<div class='dimension_col'>"; $out .= "<label>{$label_needlemin}: <input type='number' step='0.5' min='0' style='width:100px' name='{$this->name}_needlemin' id='Inputfield_{$this->name}_needlemin' value='{$value->needlemin}'/></label>"; $out .= "</div>"; $out .= "<div class='dimension_col'>"; $out .= "<label>{$label_needlemax}: <input type='number' step='0.5' min='0' style='width:100px' name='{$this->name}_needlemax' id='Inputfield_{$this->name}_needlemax' value='{$value->needlemax}'/></label>"; $out .= "</div>"; return $out; } /** * Process the input from the given WireInputData (usually $input->get or $input->post), load and clean the value for use in this Inputfield. * * @param WireInputData $input * @return $this * */ public function ___processInput(WireInputData $input) { $name = $this->attr('name'); $value = $this->attr('value'); $dim_names = array( 'length' => $name . "_length", 'weight' => $name . "_weight", 'needlemin' => $name . "_needlemin", 'needlemax' => $name . "_needlemax" ); // loop all inputs and set them if changed foreach($dim_names as $key => $name) { if(isset($input->$name)) { if($value->$key != $input->$name) { if(!is_numeric($input->$name) && !empty($input->$name)) { // in case the input isn't numeric show an error $this->error($this->_("Field only accepts number values")); } else { $value->set($key, (float) $input->$name); $this->trackChange('value'); } } } } return $this; } } I have tried to change different parameters but nothing works. Has anyone an idea?
  15. 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.
  16. I have output the number of items in the message: If there is one item it outputs 0. If there are more than one item it outputs the correct number. Very strange!
  17. Uuhh! Unfortunately it hides the page table if there is at least one item
  18. That code makes exactly what I want! Great! Thank you so much!!!!!!!
  19. Hello netcarver, your code as standalone works!! I have tried to combine it: $this->addHookAfter("InputfieldPageTable::render", $this, "rendereventpagetable"); public function rendereventpagetable(HookEvent $event) { // get the table field $table = $event->object; // make sure this is our field if ($table->name !== "singleeventtable") return; if (count($table->attr("value")) == 0) { $this->error('Achtung! Sie haben noch keine Termine erstellt'); //START $this->addHookAfter("ProcessPageEdit::buildFormContent", function($event) { $wrapper = $event->return; $wrapper->singleeventtable->collapsed = Inputfield::collapsedHidden; }); //END } } But in this case it shows me the message, but the page table field is still visible
  20. I can set it to hidden in the settings - but why should I do that? I dont understand what you mean in this case???
  21. I have tried it in these ways: $table->collapsed = Inputfield::collapsedHidden; $table->collapse = Inputfield::collapsedHidden; $table->collapsed = "hidden"; $table->collapse = "hidden"; For example this works: $table->label = "test"; The label will be replaced by the word "test".
  22. No this doesnt work either. I have also tried to add a specific css class to the page table field in this way: $table->addClass('myClassName'); But this will also be ignored. It seems that the page table field is a little bit different like other inputfields.
  23. Sorry but I cannot get it to work. I have tried it with this hook function. public function rendereventpagetable(HookEvent $event) { // get the table field $table = $event->object; // make sure this is our field if ($table->name !== "singleeventtable") return; if (count($table->attr("value")) == 0) { $this->message('Noch keine Termine erstellt'); $table->collapse = "hidden"; } } It shows me the message "Noch keine Termine erstellt" (in English: No events created), but the page table is still visible. Can you point me into the right direction?
  24. Aah, you mean something like this: https://gist.github.com/somatonic/c9db5c43f10d050bb14d I will try this way out. Thanks
×
×
  • Create New...