-
Posts
53 -
Joined
-
Last visited
Everything posted by *Most Powerful Pony!*
-
//You create a template in which we poke exactly the fields that interest us. //Name it "form_callback" //In theory, we can not even create a page for a form template //(or do it on the fly using the class NullPage). //But it is better to create, it will allow us to use the download file. //Further, on the page where the form should be, //we create a handler at the top, and print out the form below based on the handler. $pageForm = $page->child('template=form_callback, include=all'); //get page with template $templateMessage = $templates->get('message'); //template for conservation requests //superstructure $fieldsSkip = array(); $fieldsRequired = array('phone'); $fieldsRows = array('body' => 6); //Create Form $form = $modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; //Get field from form page $inputfields = $pageForm->getInputfields(); //add field to form foreach($inputfields as $inputfield) { if(in_array($inputfield->name, $fieldsSkip)) continue; if(in_array($inputfield->name, $fieldsRequired)) $inputfield->required = true; if(array_key_exists($inputfield->name, $fieldsRows)) $inputfield->rows = $fieldsRows[$inputfield->name]; $form->add($inputfield); } //add custom field "submit button and confirm read rules $checkbox = $modules->get("InputfieldCheckbox"); $checkbox->name = "checkbox"; $checkbox->label = 'I have read the terms and conditions'; $checkbox->skipLabel = 2; // 2 dont output label in name $checkbox->required = 1; $form->add($checkbox); //add to form $submit = $modules->get("InputfieldSubmit"); $submit->name = "submit"; $submit->label = 'Submit'; $submit->value = 1; $checkbox->required = 1; $form->add($submit); //Check the data post if($this->input->post->submit) { $form->processInput($this->input->post); //Check data if(count($form->getErrors())) { //Get new error via validation ob_start(); echo "<xmp>"; foreach($form as $field) { if(count($field->getErrors())) { $name = $field->name; $errors = $field->getErrors(true); //true - Clean error stack $error = $errors[0]; echo "$name -> $error\n"; //output fieldname and error message } } echo "</xmp>"; $errorsAsForm = ob_get_contents(); ob_end_clean(); } else { $pageForm->setOutputFormatting(false); //necessarily have to create page $pageForm->set('name', date('Y-m-d_H-i-s', time())); //set new name url $pageForm->set('template', $templateMessage); //set need template foreach($form as $field) { $pageForm->set($field->name, $field->value); //set data } $pageForm->removeStatus(Page::statusHidden); //clean old status $pageNew = $pages->clone($pageForm, $page); //Create message page and defined this $pageForm->setOutputFormatting(true); } } //The next steps depend on you //You can display the form in a standard way, //though if it is filled with errors entered data will //not be lost and errors prompt standard way //in precisely what fields they were admitted. $form->render() //But personally, I am! I love to display the form with your layout, it helps to do ever//ything as I want it, or how it has implemented a front-end //just example via my project with output image and code for ajax image loaded <form method="post" action="<?=$page->url?>" enctype="multipart/form-data"> <? foreach ($form as $inputfield) { $label = $inputfield->label; $desc = $inputfield->description; $name = $inputfield->name; $required = $inputfield->required ? ' required':''; ?> <?if($inputfield == 'InputfieldTinyMCE'){?> <label class="text"> <span class="desc"> <?if($inputfield->skipLabel != 2){?> <b><?=$label?></b> <?if($desc){?><i><?=$desc?></i><?}?> <?}?> </span><span class="text"> <textarea name="<?=$name?>" rows="<?=$inputfield->rows?>"<?=$required?>></textarea> </span> </label> <?}elseif($inputfield == 'InputfieldSubmit'){?> <label class="submit"> <span class="desc"></span><span class="text"> <button class="button" name="<?=$name?>" type="submit" value="1"<?=$required?>><?=$label?></button> </span> </label> <?}elseif($inputfield == 'InputfieldCheckbox'){?> <label class="checkbox"> <span class="desc"></span><span class="text"> <input name="<?=$name?>" type="checkbox" value="1"<?=$required?>> Подтверждаю, что согласна с <a href="">условиями конкурса</a> и мне больше 18 лет </span> </label> <?}elseif($inputfield == 'InputfieldImage' || $inputfield == 'InputfieldImagePony'){?> <label class="files"> <span> <span class="desc"> <b><?=$label?></b> </span><span class="text"> <div class="input"> <div class="button"> Загрузить фото<input name="<?=$name?>[]" type="file" multiple="multiple" accept="image/*"<?=$required?>> </div> <?if($desc){?><em><?=$desc?></em><?}?> </div> <div class="list"><? foreach ($pageForm->photos as $key => $value) { if($value) { $photo = $pageForm->photos->get($key); ?> <div class="item" data-filename="<?=$photo->name?>"> <div class="del"></div> <img src="<?=$photo->size(90, 90)->url?>" alt=""> </div> <? } } ?></div> </span> </span> </label> <?}else{?> <label class="text"> <span class="desc"> <?if($inputfield->skipLabel != 2){?> <b><?=$label?></b> <?if($desc){?><i><?=$desc?></i><?}?> <?}?> </span><span class="text"> <input name="<?=$name?>" type="<?=$inputfield->type?>"<?=$required?>> </span> </label> <?}?> <?}?> <? $tokenName = wire('session')->CSRF->getTokenName(); $tokenValue = wire('session')->CSRF->getTokenValue(); $tokenField = "<input type='hidden' id='_post_token' name='$tokenName' value='$tokenValue'>"; ?> <input type="hidden" id="_post_token" name="<?=$tokenName?>" value="<?=$tokenValue?>"> if($config->ajax && isset($_SERVER['HTTP_X_FIELDNAME'])) { $oid = ob_start(); $form->processInput($this->input->post); $ajaxResponse = ob_get_contents(); ob_end_clean(); $ajaxResponse = json_decode($ajaxResponse, true); $ajaxResponse = $ajaxResponse[0]; foreach($form as $field) { if($field->name == 'photos') { if($ajaxResponse['error'] == null){ $photo = $field->value->last(); $thumb = $photo->size(90, 90); $ajaxResponse['markup'] = '<div class="item" data-filename="'.$photo->name.'"><div class="del"></div><img src="'.$thumb->url.'" alt=""></div>'; $files[$photo->name] = true; $session->reg_files = $files; } $ajaxResponse['errors'] = $form->getErrors(true); echo json_encode($ajaxResponse); } } exit(); } $('form:eq(0)').each(function(){ var form = $(this) var url = form.attr('action') var token = form.find('#_post_token') var tokenName = token.attr('name') var tokenValue = token.val() var filesUpload = form.find("input[type=file]").get(0) var fieldName = filesUpload.name.slice(0,-2) var fileList = $(filesUpload).parents('label').find('.list:eq(0)') if(fileList.find('.item').length) $(filesUpload).removeAttr('required'); function uploadFile(file) { var progressBar = $('<div class="progressBar"><div class="over">' + file.name + ' - ' + parseInt(file.size / 1024, 10) + ' kb</div><div class="bar" style="width:0%"></div></div>') var xhr = new XMLHttpRequest() xhr.upload.addEventListener("progress", function (e) { if(e.lengthComputable) { var completion = (e.loaded / e.total) * 100 progressBar.find('.bar').width(completion + "%") if(completion > 4) { progressBar.find('.over').html("Загрузка - " + parseInt(completion) + "%") } } }, false) xhr.addEventListener("load", function() { var response = $.parseJSON(xhr.responseText) if(response.error) { } else { var markup = $(response.markup) fileList.append(markup) fileList.append(' ') if(fileList.find('.item').length) $(filesUpload).removeAttr('required'); } progressBar.remove() }, false) // Here we go xhr.open("POST", url, true) xhr.setRequestHeader("X-FILENAME", file.name) xhr.setRequestHeader("X-FIELDNAME", fieldName) xhr.setRequestHeader("X-" + tokenName, tokenValue) xhr.setRequestHeader("X-REQUESTED-WITH", 'XMLHttpRequest') xhr.setRequestHeader("Content-Type", "application/octet-stream") xhr.send(file); fileList.append(progressBar) } function traverseFiles(files) { for(var i=0, l=files.length; i<l; i++) { var extension = files.name.split('.').pop().toLowerCase() uploadFile(files) } } filesUpload.addEventListener("change", function(e) { traverseFiles(this.files) e.preventDefault() e.stopPropagation() this.value = '' }, false) })
-
I'm use inputfieldForm module for custom form at front-end on my project and except CFRS there is necessary an input Captcha, it would be healthy if it is available in modules by default!
-
For example: It is necessary for you that all photos in galleries of "participants" would be in jpeg. But different types are allowed for loading, and all of them will be cut off in compliance with the type. I suggest to choose expansion in which the reduced copies of the image will be converted, it can be both control for a field, and expansion for API Image $image->ext() //jpg $newImage = $image->ext('png') $newImage->ext() //canonical png convert
-
It will allow not to allow file load .psd with expansion on .jpg. Example: I have an external form. In type of a field it is specified (to allow.jpg.jpeg). But it is enough to rename only expansion as it will be possible to load and.psd and.png and.pdf and.php. Besides, everyone will be processed on a miscellaneous, instead of as jpg. For the sake of dough I suggest to load psd renamed into jpg
-
Page as Symbolic link other Page
*Most Powerful Pony!* replied to *Most Powerful Pony!*'s topic in Wishlist & Roadmap
http://en.wikipedia.org/wiki/Canonical_link_element <link rel="canonical" href="http://www.example.com/directory/page/"> -
Page as Symbolic link other Page
*Most Powerful Pony!* replied to *Most Powerful Pony!*'s topic in Wishlist & Roadmap
Such way it is necessary to watch use of segments, the page has to have plus the template, by default segments are limited to 4. I want to see the similar decision for realization of a multi parents. = своё содержимое as this contain -
Problem persists also in the latest developer version ProcessWire 2.3.9 © 2013 Ryan Cramer
-
It would be cool to designate page symlink another page. That would need addressing at a different page (symlink), runs and shows the referenced page, including all its content*, so would the same content was available in two completely different locations. This is useful for example for multicategory, availability of books both the author and the year of release while preserving the path in the address bar.
-
Fieldtype Integer, dont save option max, min with value 0 (zero). Positive values (> 0) and negative (<0), perfectly preserved. Without 0, built-in filter is not working properly.