Jump to content

Harmster

Members
  • Posts

    137
  • Joined

  • Last visited

Everything posted by Harmster

  1. Hey hey Now my title might seem confusing but this is essentially what i have: $items = $pages->find("template=match|notification, summoner_id=$summoner_string, sort=-create_date, limit=15"); And I want a field called notification_type to be equal to a certain amount of values, now what I first thought would work would be notification.notification_type = something but it doesn't The other template doesn't have the field notification_type so I cant just put it in there Any help? thanks
  2. Hey, The Form API has CSRF protection build in, but if you for some reason don't want to use the API you can however use the CSRF protection. Its very simple but it took some time for me to find out, so i figured i share my findings with the rest. What is CSRF? First you need to create a token and a token name you do that as following: $tokenName = $this->session->CSRF->getTokenName(); $tokenValue = $this->session->CSRF->getTokenValue(); Very simple. Now what you want to do is create a hidden input field like this: $html .= '<input type="hidden" id="_post_token" name="' . $tokenName . '" value="' . $tokenValue . '"/>'; Now this will generate something that will look like this: You are done on the form side. You can now go to the part where you are receiving the post. Then use: $session->CSRF->validate(); This will return true (1) on a valid request and an exception on a bad request. You can test this out to open up your Firebug/Chrome debug console and change the value of the textbox to something else. Basicly what this does is set a session variable with a name (getTokenName) and gives it a hashed value. If a request has a token in it it has to have the same value or it is not send from the correct form. Well I hope I helped someone.
  3. Hey, I've already posted a post about this earlier: http://processwire.com/talk/topic/3727-does-input-urlsegments-mess-with-post/ And I've fixed that problem at the time to switch from WAMP to XAMPP server. I didnt know why it worked but you didn't hear me complain. Now I've uploaded my website to a webhosting service and I once again encounter this problem... So here's the situation. I try to post a comment from my homepage to a page called /actions/post-comment (this has a template) This template contains the following code: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ echo 'POST HAS BEEN SET'; }else{ ?> <form action="<?php echo $config->urls->root;?>actions/post-comment/" method="post"> <input type="text" name="harm"/> <input type="submit" value="test" /> </form> <?php } ?> This was for testing purposes. If I post here it does show POST HAS BEEN SET. Now this is my form on my homepage (Taken fromt he HTML sourcecode) <form action="/actions/post-comment" method="post"> <input type="text" placeholder="comment" autocomplete="off" name="comment"/> </form> But THIS doesn'r display it. I am using PHP5 and standart .htaccess My hosting provider is Go Daddy and I am just stuck on this... I think it has to do something with htaccess but I have no idea what and I have no idea where to look. EDIT: As mentioned in the previous post, i've tried addint a / to the request but no Please help, Much appriciated.
  4. Sooo... I need to add a / to the url? I tried it and it doesnt work? EDIT: And LanguagePageNames isnt installed
  5. Hey, I've encountered the weirdest thing ever in my history of PHP So i'm trying to get my forms working and after hours and hours of frustrating debugging i found out that $_SERVER['REQUEST_METHOD'] Is always GET... So i started testing, i've created a template: test and on the root page i added a page so my website url = http://localhost/social/test (Social being root folder) And made this code: <?php echo $_SERVER['REQUEST_METHOD']; if($_SERVER['REQUEST_METHOD'] == 'POST'){ echo $input->post->comment; } ?> <form action="" method="post"> <textarea name="comment"> Comment </textarea> <input type="text" name="a"> <input type="submit"/> </form> As a test. It echoes POST and the value submitted, as expected. This code however does not work on a different templte (http://localhost/social/pages/post-comment) that does have urlSegments enabled. and it displays GET... (When submitted ofcourse) When i change my test template to allow urlSegments it still doesnt work. This happened in an almost fresh install of PW. What the hell is going on? And how do i fix it? Its really frustrating and I can't really continue. EDIT: Oh. I use WAMP server on Windows 8 Thanks!
  6. Error: Exception: Method Page::first does not exist or is not callable in this context (in C:\wamp\www\social\wire\core\Wire.php line 232) Thats the result Wanze. Thats what I expected since var_dump returns NULL... So theres no array or object returned... This is how I make the repeater values: foreach($match->statistics->array as $statistic){ $s = $p->statistics->getNew(); $s->stat_type = $statistic->statType; $s->data_version = $statistic->dataVersion; $s->value = $statistic->value; $s->future_data = $statistic->futureData; $s->save(); } And this is how i try to get the items: for($i=1;$i<7;$i++){ $item = $this->pages->find("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1"); if($item->id){ $item1 = $item->first(); $this->html .= $item1->value; } } Also tried: for($i=1;$i<7;$i++){ $item = $this->pages->get("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1"); if($item->id){ $item1 = $item->first(); $this->html .= $item1->value; } } Or: for($i=1;$i<7;$i++){ $item = $this->pages->find("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1"); if($item->id){ $val= $item->first()->value; $this->html .= $val; } }
  7. What exactly do you mean with Widget? I've never used a thing called widget.... But if you render a page with $page->render(); why not echo $page->id?
  8. I've tried it but still the same result... Any other ideas?
  9. Hey. I've got a template with a statistics repeater field the repeater field contains 4 fields -statistics --stat_type --data_version --value --future_data In the same template there's also a field called game_id. When I use the following selector I get a page back but I can't access the value: $pages->get("statistics.stat_type=ITEM1, game_id=877760255"); I've used the Selector module and it returned 2 pages, but thats because it uses find. How can i access the value field?
  10. Yeah it does work. I think i was thinking too quick and the docs confused me thanks a lot!
  11. Are you using the field as a unique value? If so I woulnd't use these methods...
  12. Hey, So I am experimenting with websockets and I've got a server running but now I want to be able to save some of the I/O to pages. I thought i just bootstrap (http://processwire.com/api/include/) to my server and it'll work. No This is the message i get running CMD.exe: And the server crashes and disconnects all clients. This is the entire code of the server.php: (Located in the PW Root folder). <?php include("C:\wamp\www\social\index.php"); // prevent the server from timing out set_time_limit(0); // include the web sockets server script (the server is started at the far bottom of this file) require 'class.PHPWebSocket.php'; // when a client sends data to the server function wsOnMessage($clientID, $message, $messageLength, $binary) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); // check if message length is 0 if ($messageLength == 0) { $Server->wsClose($clientID); return; } //The speaker is the only person in the room. Don't let them feel lonely. if ( sizeof($Server->wsClients) == 1 ){ $Server->wsSend($clientID, "There isn't anyone else in the room, but I'll still listen to you. --Your Trusty Server"); print($item->text); } else //Send the message to everyone but the person who said it foreach ( $Server->wsClients as $id => $client ) if ( $id != $clientID ){ $Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\""); } } // when a client connects function wsOnOpen($clientID) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); $Server->log( "$ip ($clientID) has connected." ); $item = $wire->pages->get('template=item'); $Server->log($item->text); //Send a join notice to everyone but the person who joined foreach ( $Server->wsClients as $id => $client ) if ( $id != $clientID ) $Server->wsSend($id, "Visitor $clientID ($ip) has joined the room."); } // when a client closes or lost connection function wsOnClose($clientID, $status) { global $Server; $ip = long2ip( $Server->wsClients[$clientID][6] ); $Server->log( "$ip ($clientID) has disconnected." ); //Send a user left notice to everyone in the room foreach ( $Server->wsClients as $id => $client ) $Server->wsSend($id, "Visitor $clientID ($ip) has left the room."); } // start the server $Server = new PHPWebSocket(); $Server->bind('message', 'wsOnMessage'); $Server->bind('open', 'wsOnOpen'); $Server->bind('close', 'wsOnClose'); // for other computers to connect, you will probably need to change this to your LAN IP or external IP, // alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME'])) $Server->wsStartServer('127.0.0.1', 9300); ?>
  13. I tried it out and It doesnt seem to work as I expected... Because the thing is if i change the object from an InputfieldWrapper to an IputfieldForm it acctually works as expected but in that case I can't create my form WITHIN the form without the code being a dick.
  14. Thanks for your fast reply I've tried it but unfortunately it doesn't work... Are you sure this is the only thing I need to add?
  15. What a coincidence, I am also struggling with this yet again. From what I had it went like this -form -wrapper -wrapper and those wrapper titles were displayed as the tabs. Can I use a wrapper too? instead of a form? And if not, how do i put my form, which i want to send with post inside one of the tabs? I dont get it to work correctly... Here's my code: private function _renderInterface() { $wrapper = new InputfieldWrapper(); $wrapper->attr('id', 'youtube_wrapper'); //$wrapper = $this->modules->get('InputfieldWrapper'); //$form->attr('id','ga_form'); //$form->attr('method', 'post'); $wrapperEen = new InputfieldWrapper(); $wrapperEen->attr('id','overview_wrapper'); $wrapperEen->attr('title',$this->_('Overview')); $wrapperTwee = new InputfieldWrapper(); $wrapperTwee->attr('id','upload_wrapper'); $wrapperTwee->attr('title',$this->_('Upload')); $field = new InputfieldMarkup(); $field->columnWidth = 100; $videos = wire('pages')->find('template=video'); $table = $this->modules->get("MarkupAdminDataTable"); $table->setEncodeEntities(false); $rows = array(); $header = array( $this->_x('Title', 'list-thead'), $this->_x('Thumb', 'list-thead'), ); foreach($videos as $video){ $video_data = $this->get_info_single_video($video->video_id); $title_html = "<a href=\"/processwire/youtube-module/video?id=" . $video->video_id . "\">" . $video->title . "</a>"; $thumb_html = "<img src=\"". $video_data->{'entry'}->{'media$group'}->{'media$thumbnail'}[0]->url ." \"/>"; $table->row(array($title_html, $thumb_html)); } $html .= $table->headerRow($header)->render(); $field->attr('value',$html); $wrapperEen->append($field); $field = $this->modules->get("InputfieldMarkup"); $wrapperTwee->append($field); if(isset(wire('input')->post->video_title) && isset(wire('input')->post->video_description)){ $video_title = stripslashes( wire('input')->get->video_title ); $video_description = stripslashes( wire('input')->get->video_description ); $response = $this->upload_video($video_title, $video_description); if($response->token != ''){ $nexturl = "http://followmylegends.com/processwire/youtube-module/uploaded"; $upload_form = new InputfieldForm(); $upload_form->attr('action', $response->url . "?nexturl=" . urlencode( $nexturl ) ); $upload_form->attr('method', 'post'); $field = wire('modules')->get("InputfieldFile"); $field->label = "Images"; $field->description = "Select your video."; $field->required = 1; $field->attr("name+id",'images'); $field->destinationPath = $upload_path; $field->maxFiles = 1; $upload_form->add($field); $submit = wire('modules')->get("InputfieldSubmit"); $submit->description = 'Proceed to video upload'; $upload_form->append($submit); $token = new InputfieldHidden(); $token->attr('name', 'token'); $token->attr('value', $response->token); $wrapperTwee->append($upload_form); $wrapperTwee->append($token); } }else{ $upload_form = new InputfieldForm(); $upload_form->attr('action','/processwire/youtube-module/upload'); $upload_form->attr('method','post'); $field = new InputfieldText(); $field->attr('name+id', 'video_title'); $field->label = "Title"; $field->description = 'Enter a title for your new video'; $upload_form->append($field); $field = new InputfieldText(); $field->attr('name+id', 'video_description'); $field->label = "Description"; $field->description = 'Enter a description for your new video'; $upload_form->append($field); $field = wire('modules')->get("InputfieldSubmit"); $field->description = 'Proceed to video upload'; $upload_form->append($field); $wrapperTwee->append($upload_form); } $wrapper->append($wrapperEen); $wrapper->append($wrapperTwee); return $wrapper->render(); }
  16. Hey, I am working on my module and i need to upload a file, a video in this case this is my code: $video_upload = new InputfieldFile(); $video_upload->attr('name', 'file'); $form->append($video_upload); This is what I get on my form. If i drag my video in it and the video starts playing (Google Chrome) Now i've gopt a few questions about this 1- How do i get a select file button in there? 2- How do i get the video in there? Thanks in advance
  17. Hey, I am busy on creating a PW Youtube module. Now when i try to make the interface in PW ( the youtube tab) I get this erro: Now this is my _install() code: public function ___install() { $page = $this->pages->get('template=admin,name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = $this->templates->get('admin'); $page->parent = $this->pages->get($this->config->adminRootPageID); $page->title = 'Youtube'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } I understand that the proecss = $this, which in this case is Youtube. but why do all my other modules work but this one doesnt? and how can i fix it...
  18. Will try that now... Hope it works it really starts to frustrate me >.<
  19. I've emptied both folders, with no result. The folder has 777 and still doesn't work. I am kinda stuck since i really need to access the admin panel. Well i guess i'll try to redo the whole process.
  20. No I didnt, I did empty it now though and it still doesn't work. Does it matter that it is in a subdir with an another PW setup in the rootdir?
  21. Hey, I am busy with a school project but I get stuck when i placed my website from localhost to my domain. My site runs on a subfolder. /daplays/ /site/assets and all it's subfolders are 777. I've tried to change things around in the .htaccess but with no result. Could someone please help me ? Thanks in advance
×
×
  • Create New...