-
Posts
47 -
Joined
-
Last visited
Everything posted by lecrackffm
-
Hello, thanks to many great posts in this Forum i managed do create a working script which saves a Form submit to a new page (including a file upload) via AJAX. I still have to questions : 1. Does anyone see a security risk in this script? Its the first time im building something like that. 2. How can i prevent direct access via the url. i would like to throw a Wire404Exception then. I tried if($input->post-name) {...} .. but that gives me a 404 on the AJAX request if the name is left empty , which is not what i want. Thanks for your support! <?php $msg = ['name' => ['error' => 'Kein Name angegeben'], 'vorname' => ['error' => 'Kein vorname angegeben'], 'file' => ['error' => 'Keine Datei hochgeladen'], 'wire' => ['error' => 'Unerwarteter Fehler, bitte nochmal versuchen'], 'success' => ['success' => 'Bestellung erfolgreich abgeschlossen'] ]; //Check if all input fields have Data. Everything will be checked via javascript in the frontend as well. if(empty($_POST['name'])) { echo json_encode($msg['name']); return false; } if(empty($_POST['vorname'])) { echo json_encode($msg['vorname']); return false; } if(!isset($_FILES['doc'])|| $_FILES['doc']['error'] == UPLOAD_ERR_NO_FILE) { echo json_encode($msg['file']); return false; } $uploadPath = $config->paths->assets . "files/tmp_uploads/"; $doc = new WireUpload('doc'); $doc->setMaxFiles(1); $doc->setOverwrite(false); $doc->setDestinationPath($uploadPath); $doc->setValidExtensions(array('pdf', 'jpg', 'png', 'jpeg')); $documents = $doc->execute(); if(!count($documents)) { echo json_encode($msg['wire']); return false; } $np = new Page(); $np->template = $templates->get('new-order'); $np->parent = $pages->get('/bestellungen/'); //Populate fields with sanitized data $np->title = "Neue Bestellung von " . $sanitizer->text($input->post->name); $np->orderName = $sanitizer->text($input->post->name); $np->orderVorname = $sanitizer->text($input->post->vorname); $np->save(); foreach ($documents as $document) { $pathname = $uploadPath . $document; $np->orderFile->add($pathname); unlink($pathname); } $np->save(); echo json_encode($msg['success']); ?>
-
Hello everyone, i am building a little 'shop-like' element for a clients Homepage (no direct payment) Its my first Approach working with php besides very basic php and Processwire stuff, so i am a litte lost here. I want to use KnockoutJs for getting User Input, process the Data on the Server (pulling actual prices from a page) and send a single JSON Object, which holds all the Data needed for display in the UI back to knockout . The data will be send on every "keyup" in the front end. so i want the "checkout" array to be updated every time. I have some code already and it looks good so far. But obviously, with every ajax request ill get a new object with only the newest data back. <?php // Data comming on every "keyup" $hardMenge = $input->get->entities("hard"); $softMenge = $input->get->entities("soft"); // more to items will follow // Different products to choose from (actual prices will come from pages later) // More Products with different requierements will be added class Softcover { public $menge; public $preis; public function __construct($menge) { $this->menge = $menge; $this->preis = $menge * 10; } } class Hardcover { public $menge; public $preis; public $letter; public function __construct($menge, $letter) { $this->menge = $menge; $this->preis = $menge * 10; $this->letter = $letter; $this->total = $letter * .5 + $this->preis; } } $softy = new Softcover($softMenge); $harty = new Hardcover($hardMenge,2); $checkout = array(); $softOut = array("soft" => array("menge" => $softy->menge, "preis" => $softy->preis)); $hardOut = array("hart" => array("menge" => $harty->menge, "preis" => $harty->preis, "mitGravur" => $harty->total)); if (isset($softy) && ($softy->menge > 0)) { array_push($checkout, $softOut); } if (isset($harty) && ($harty->menge > 0)) { array_push($checkout, $hardOut); } // JSON object back to knockoutJS echo json_encode($checkout); My guess is i might use sessions eg $session here to keep all the data in the "checkout" array, and only refresh relevant parts of it on frontend "keyup"events. How could i use sessions to achieve that? Or is my Approach going nowere and i need to rethink everything? Thanks for helping out.
-
Thanks for helping out, Zeka!
-
It works! Thanks. Can anyone explain, why?
-
Hello, im facing a quite odd problem: when im trying to include a piece of code with $files->include it renders the content, in this case a complete <section> ... </section> correctly, but also an additional "1" after the closing tag. When placing the included code directly in the template all works as aspected. So it has to do something with $files->inlcude, right? Thanks, Gregor
-
Thanks @LostKobrakai. That solved my problem. I got it working with jquery now. My js above is giving me a "Uncaught SyntaxError: Unexpected end of JSON input" ....
-
Hello, since hours i am struggeling to get an ajax call to an page field working. i think im doing something fundamentally wrong. The Idea is to load some html markup for larger screen sizes. If i put a .php file with the markup outside the 'site' folder it works fine with a basic XMLHttpRequest. But if i want to have the markup stored in a textfield on my 'settings page' within the template folder i have no success. I tried to follow some tips from this thread as well: my settings.php looks like this: <?php if($config->ajax) { $json = array( 'id' => $page->id, 'title' => $page->title, 'markup' => $page->markup ); echo json_encode($json); return; } and my inline javascript like this ( wrapped in enquire.js): <script type="text/javascript"> enquire.register('screen and (min-width: 700px)', { match: function() { var xhr = new XMLHttpRequest(); xhr.onload = function(){ if(xhr.status === 200){ data = JSON.parse(xhr.responseText); document.getElementById('hero').innerHTML = data.markup; } } xhr.open('GET', 'settings.php', true); xhr.send(null); }, unmatch: function() { } }); </script> <section id="hero"> </section> Like this, i am just getting a 404 , and if i try with a path i get a 403 forbidden. Im entirely confused, maybe someone can help. Thanks a lot.
-
two questions about rendering a navigation
lecrackffm replied to lecrackffm's topic in General Support
@horstThanks for the explanation.- 9 replies
-
- onepage
- navigation
-
(and 1 more)
Tagged with:
-
two questions about rendering a navigation
lecrackffm replied to lecrackffm's topic in General Support
The solution @horst posted worked for me. I tried with $id++ at the end as well. But then it did not render anything. Thank you for your support!- 9 replies
-
- onepage
- navigation
-
(and 1 more)
Tagged with:
-
two questions about rendering a navigation
lecrackffm replied to lecrackffm's topic in General Support
Thank you very much for the fast help, both of you. I will test it asap as i am back at my desktop! Have a nice weekend!- 9 replies
-
- onepage
- navigation
-
(and 1 more)
Tagged with:
-
Hello everyone, i have written a simple function to render the Navigation for my "Onepager" Here is the code: <?php function renderOnepagenav($onepageroot) { $sections = $onepageroot->children; echo "<ul>"; $id = ''; foreach ($sections as $item) { $id ++; echo "<li><a href='#section-$id'>$item->title</a></li>"; } echo "</ul>"; } Every Sektion is a child-page of home in the backend. It works fine but i would like to add two modifications, where i need your help: 1. i would like to skip the first (child-)page. 2. I would like to add a class only to the first rendered <li> Element. All kind of advice is highly appreciated. Thank you, Gregor
- 9 replies
-
- onepage
- navigation
-
(and 1 more)
Tagged with:
-
@Robin S thank you for the explanation.
-
Thank you, thats a good advice. Also the profields multiplier seems good for this kind of task, right?
-
I got it. The Repeater i just installed does the job. But im still open to other ways to accomplish that, just for getting to know PW better. Thanks
-
Hello, im porting my first static site to PW and still trying to get my head around all the options and logics..maybe you can help out. I have a simple list (ul>li) of Names on the page, which i want my client to alter at any time. Right now, the only option i see is to create a textfield with the CKEditor. Is there a more more straight foreword way to accomplish this, like creating one field in which my client can put comma separated names, and i loop through this field in the template? I tried to find something like this in the cheatsheet but im still struggling with all the options. Thanks for your help.
-
pointing to files using $config->urls->assets within a php tag
lecrackffm replied to lecrackffm's topic in Getting Started
$config->paths did the trick. Still a lot to learn. Thanks a lot for the fast and kind support.- 6 replies
-
- php
- file_get_contents
-
(and 1 more)
Tagged with:
-
pointing to files using $config->urls->assets within a php tag
lecrackffm replied to lecrackffm's topic in Getting Started
@blynx Wow, thanks. ill have a closer look at your function. And yes, i am ffm based- 6 replies
-
- 1
-
- php
- file_get_contents
-
(and 1 more)
Tagged with:
-
pointing to files using $config->urls->assets within a php tag
lecrackffm replied to lecrackffm's topic in Getting Started
Thanks for the fast support! oh sure, i forgot about the correct arrows writing my post. The curly brackets are giving me the correct path now, thanks for that. I am still i am getting a Warning: file_get_contents(/site/assets/img/icons/vibra.svg): failed to open stream: But the files are there for sure... ill figure that out.. Thanks for the fast support!- 6 replies
-
- php
- file_get_contents
-
(and 1 more)
Tagged with:
-
Hello everyone, this is my first post here, and i hope its the right place for my question. I am getting started with PW and right now, im trying to bring a existing static Site to PW In this static site i was working with some PHP to import svg code echo file_get_contents("img/icons/ticket.svg") I placed the img folder in the assets folder but now i am having troubles to point at this file using $config->urls->assets i was trying to do something like echo file_get_contents("$config-urls-assets/img/icons/ticket.svg") but of course this fails and as i am not quite good with PHP i do not know how to nest this php to get what i want. I don`t want to use fields to store the svg code, because i need different icons on one page and i do not want to create multiple field for that. Any advice is highly appreciated. Thank you.
- 6 replies
-
- php
- file_get_contents
-
(and 1 more)
Tagged with: