fnode
-
Posts
17 -
Joined
-
Last visited
Posts posted by fnode
-
-
Super awesome!
That is a crazzzzy form builder!
Thank you!
-
1
-
-
Code is working now! Thanks!
libs/paypal/ipn.php
<?php include ("../../index.php"); $productid = $wire->pages->get(1332); var_dump($productid); ?>-
1
-
-
Thank you Pete!
-
Hello Community,
I have a directory structure like this:
[website]
|- libs // This folder is not part of PW
|- paypal
|- ipn.php
|- site
|- wire
The problem is that I cannot access $pages inside /website/libs/paypal/ipn.php.
Paypal IPN will point to this file: http://mysite.com/libs/paypal/ipn.php
<?php $productid = $pages->get(1332); var_dump($productid); // read the post from PayPal system and add 'cmd' $req = 'cmd=' . urlencode('_notify-validate'); foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com')); $res = curl_exec($ch); curl_close($ch); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } ?>Thanks!
-
Thank you, Soma for your help. It's working now. The code you gave me, helped me. I just added the the following:
<?php if($p->numChildren){ foreach($page->get($p->name) as $fo){ if(count($fo->get($fo->name))){ foreach($fo->get($fo->name) as $f1){ $fielddata->import($f1); } } } } else { foreach($page->get($p->name) as $fo){ $fielddata->import($fo); }FROM YOUR CODE
then how about like this?
function Pagefields(Page $page){ $fielddata = new PageArray(); foreach($page->uses as $p){ foreach($page->get($p->name) as $fo){ if(count($fo->get($fo->name))){ foreach($fo->get($fo->name) as $f1){ $fielddata->import($f1); } } } } return $fielddata; } foreach(Pagefields($page) as $p){ echo "<p>$p->title</p>"; }.... edited code a little.
MY FINAL VERSION
<?php function Pagefields(Page $page){ $fielddata = new PageArray(); // Nice ! foreach ($page->uses as $p){ if($p->numChildren){ // line added foreach($page->get($p->name) as $fo){ if(count($fo->get($fo->name))){ foreach($fo->get($fo->name) as $f1){ $fielddata->import($f1); } } } } else { // lined added foreach($page->get($p->name) as $fo){ $fielddata->import($fo); } } } #endof: foreach($page->uses as $p){} return $fielddata; // Return me some data! } foreach(Pagefields($page) as $p){ echo "<p>$p->title</p>"; // Yes, I got data! }Thank you again for your big help. Awesome Community!

-
1
-
-
Yes, you are correct I had to use strtolower($fo->title) for it to match or it will not work. $fielddata needs to returned data in each foreach loop.
then how about like this?
function Pagefields(Page $page){ $fielddata = new PageArray(); foreach($page->uses as $p){ foreach($page->get($p->name) as $fo){ if(count($fo->get($fo->name))){ foreach($fo->get($fo->name) as $f1){ $fielddata->import($f1); } } } } return $fielddata; } foreach(Pagefields($page) as $p){ echo "<p>$p->title</p>"; }.... edited code a little.
My code
<?php function Pagefields(Page $page){ $fielddata = new PageArray(); foreach($page->uses as $p){ //var_dump($p->title); // OUTPUTS. instances and categories foreach($page->get($p->name) as $fo){ //var_dump($fo->title); // OUTPUTS. Categories and 2D // I need to $fielddata also in this foreach loop, so it returns (categories) in this page. // Or, it will not return [2D] as the selected item in categories. // But is not returning $fielddata->import($fo); // I changed the name to match with (categories) it was category before. So, I do not use strtolower($fo->title) function. if(count($fo->get($fo->name))){ foreach($fo->get($fo->name) as $f1){ var_dump($f1->title); // Yes, It outputs. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. No errors if I add another instance in (instances). $fielddata->import($f1); } } } } #endof: foreach($page->uses as $p){} return $fielddata; } foreach(Pagefields($page) as $p){ //echo "<p>$p->title</p>"; //var_dump($p->title); }Thank you for helping me.
EDIT : Attached file Pic #1 Pagefields > has 2 children assets and instances, it has 2 children categories and tags. Instances Page holds Categories and Tags, as you can see in Attached file # 1 if one of them matches I will get its data. Attached file Pic #1
-
And if you do?
if(count($page->instances)){ foreach($page->instances as $instance) { foreach($instance->categories as $cat){ echo $cat->title; } } } else if($page->instances->categories){ foreach($page->instances->categories as $cat) { echo $cat->title; } } else { echo "no instances"; }Yes, that works for the first loop foreach($page->instances as $instance) {} it OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3
EDIT : It does not work in foreach($instance->categories as $cat){ } if I add another instance in (instances). I have Categories, and Tags
-
It does not work. I get Warning: Invalid argument supplied for foreach()
<?php foreach($page->instances->categories as $cat) { echo $cat->title; } -
It will be easy to change field name for every particular project. If I do not like the field name (instances) I can change to (references), something like that. The "Select Instance" field has to be in a foreach I have more (instances) in that list. For example: Categories, and Tags.
-
The [uses] field helps me not to hard-code the fields name in my page, so I can change the name of field on the fly, its more dynamic. It prevents me from opening an IDE.
-
Hello Community,
SETUP:
Fields I have (uses:Page), (instances:Page) and (categories:Page). Please see the attached file.
[ uses ] Selection of fields to render. See the attached file # 2
[ instances ] "Default" data for pages. See the attached file # 2
[ categories ] A bunch of items

CODE:
Renders the selected field from [ uses ] to the template. It's a simple way of not hard-coding the fields in your page. NOTE: Pagefields() is a function inside /site/templates/home.php
ISSUE:
I do not know how to exclude the parent's field ($fo->title) from field ($page->instances) (Categories). Which is foreach($page->{strtolower($p->title)} as $fo){} thus returning $fielddata. I want to get only the titles from ($fo->categories) and not the (Categories) title. I hope I am making sence. See the attached file # 3.
Field (uses)
Example: I select a field called (categories) from [ uses ] it outputs the title "2D". For this to work the current page or template has to have that field from [uses] or it will not work. See the attached file # 2
<?php function Pagefields(Page $page, Pages $pages, Fields $fields){ $fielddata = array(); foreach($page->uses as $p){ var_dump($p->title); // OUTPUTS. instances, categories foreach($page->{strtolower($p->title)} as $fo){ $fieldr = strtolower($fo->title); var_dump($fo->title); // OUTPUTS. Categories, 2D $fielddata[] = $fo; // Returns the title (Categories) which I don't want. I do need to return the titles inside Categories with a field called (categories). if($page->get($fieldr)!=NULL){ foreach($fo->{$fieldr} as $f1){ $fielddata[] = $f1; var_dump($f1->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3 } }#endof: if($page->get($fieldr)!=NULL){} } } #endof: foreach($page->uses as $p){} return (object) $fielddata; } foreach(Pagefields($page, $pages, $fields) as $p){ var_dump($p->title); }HARD-CODED VERSION: This is the other way of doing my code above. I do not want to hard-code the field names in my home.php file
I have debug set to TRUE and I get the following error.
<?php foreach($page->instances as $p){ foreach($p->categories as $cat){ var_dump($cat->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3 } }## Warning: Invalid argument supplied for foreach() in line 2 foreach($p->categories as $cat){}
-
Thank you, Ryan!

-
Hi, Ryan
It works perfectly!
<?php // foreach($page->assets as $inc) { if(count($inc->fileimages)) foreach($inc->fileimages as $f) echo $f->basename . '<br />'; // prints project_01.png, project_02.png }Thank you, Ryan for the help!
-
Hi,
I am using ProcessWire 2.0.
Yes, I have populated the field "fileimages" and its lowercase.
I attached 2 files, so you can see my structure for my website.
<?php // Code below works great! if I want the first image. I need all images attached. foreach ($page->assets as $inc) { if(count($inc->fileimages)){ echo $inc->fileimages->first()->basename; // prints project_01.png } } ?> -
Hi, Ryan
Thank you for your response. [Maximum files allowed] for "fileimages" is set to 0 for no limit.
I change the "max number of files" and I got an error: Notice: Trying to get property of non-object in D:\production\websites\processwire\site\templates\page.php
-
Hello, PW Community
I have 2 fields, one called "fileimages" typeof [image], second field is called "assets" typeof [Page].
The field "assets" contains the children of "Static" Page, please see structure below.
Home
|- Static
|- test_01
|- test_02
Setup > Fields
|- fileimages // typeof Image
|- assets // typeof Page # Containing the data of "Static" from above
Setup > Templates
|- page // Contains "assets"
<?php // site/templates/page.php foreach ($page->assets as $inc) { echo $inc->title // prints test_01, test_02 echo $inc->fileimages->basename; // Getting no value } ?>The issue is that I cannot access a field inside of another field which contains data. # $inc->fileimages->basename.
Great community! Thanks to Ryan for this awesome Framework!
Inputfield Dependencies in your template
in General Support
Posted
Hello,
I'm loving Inputfield Dependencies in PW 4.
I have the following fields:
Fields:
- columnOption : Page : Input type Select
..... No Section
..... Batch ?id=1016
..... Font Awesome ?id=1017
- batchClass : Text : showIf columnOption=1016 //Batch CSS Class
- batchDataIcon : Text : showIf columnOption=1016 //Batch Icon Data
- faClass : Text : showIf columnOption=1017 //Font Awesome
Template:
- column : All fields from above
For example:
I select Font Awesome and faClass:field appears I input fa-code-fork. If I choose another option, content for faClass:field still remains in my template.
How can I check if a selected option is active or not with showIf in a template. I hope I'm making sense. I attached images for you to see.
Code basic : home.php
<?php foreach ($page->column as $c) : ?> <div class="four columns icons"> <i class="icon <?php echo $c->batchClass ?>" data-icon="<?php echo $c->batchDataIcon ?>"></i> <h3><?php echo $c->title ?></h3> <p><?php echo $c->body ?></p> </div> <?php endforeach ?>Thank you!