Hello all, and thanks to those who give their time to help out those in need!
That being said, unfortunately I’m one of the latter at the moment, and would appreciate some guidance and advice on how to do what I need to do.
In a nutshell, here’s the situation:
I have a non-profit website that gives local businesses the ability to create and advertise coupons for their business for free.
Currently, I have everything working via DreamWeaver’s SPRY Javascript framework, and I’m looking to ease my work load by converting the system to PHP for ease of maintenance, along w/ SEO benefits. And I do not want to do this w/ a Database, as the coupons only have a lifespan of 2 weeks then they’re gone.
So, I’m trying to do it all w/ just XML.
That being said, I need to figure out how to port individual coupon/node info into a new dynamic page when clicked, or allow it to be emailed as an HTML email, or possibly allow it to be shared on Social Media.
So, I have a webpage that will use SimpleXML to read and output HTML from a file called “Coupons.xml”, which will have all the weekly coupons in it in XML format of course.
Each coupon’s business name will be a link/button/submit that when clicked, will use xPath and somehow collect all of that coupon’s node info only and pass it along to the next thing, be it an individual webpage created dynamically to be printed or emailed, or whatever I may need to do w/ the info.
I’ve came to the conclusion that each coupon actually needs to be treated as a form, with the Company Business Name link actually being a submit button that will collect the node info for that coupon only and pass it along. I think an invisible field should do the trick to pass the info along, though I’m open to suggestions.
The user will have a couple of options for now:
- Click the Business name » script is ran to dynamically produce a print page that will have just that coupon on it only, and user can print individual coupon.
- Each coupon will also contain a checkbox and actually be part of a larger form. If the user checks off a series of coupons, then hits a designated submit button, a dynamic page is produced w/ only those selected coupons on it for print.
- Using the same methods, the user will also have the option to email an individual coupon, or the custom print sheet of coupons they created.
That being said, since each coupon will actually be a form, I’m not sure how to designate the checkboxes to be able to retrieve the node info and pass it along to the next step as part of the larger form.
Also, I’m not sure how to make the Business Name submit button to extract and pass along the node info to the next step. I know it will probably have to use xPath, which I have working, though I’m new to it and don’t know how to use it to pass the info to the next page, which is where the invisible field will come in I’m thinking.
I hope this makes sense. Below is my code. Someone please help me sort this out and be able to pin-point coupon node info and pass it along.
Thanks in advance for any and all help!
Abs0lute
Here’s some sample code of what I have thus far:
XML Coupons:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coupons>
<coupon id="1">
<expiration>Feb. 26, 2010</expiration>
<category>Fitness</category>
<company>Some Business</company>
<deal>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </deal>
<deal2>Nullam ut diam eget metus scelerisque pulvinar ut a ipsum. </deal2>
<deal3>Nullam ut sagittis justo. Praesent massa lacus, scelerisque sit amet mollis a, lobortis at dolor.</deal3>
<extra>Some Extra Info will go here if needed</extra>
<address>123 Some Street, Someplace, World, 12345</address>
<address2>123 Some Street, Someplace, World, 12345</address2>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
<coupon id="2">
<expiration>March 26, 2010</expiration>
<category>Automotive</category>
<company>Whatchamacallits</company>
<deal>Suspendisse at lectus lectus, at blandit metus.</deal>
<deal2>Cras varius fermentum aliquet. Pellentesque habitant morbi tristique</deal2>
<address>123 Some Street, Someplace, World, 12345</address>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
<coupon id="3">
<expiration>April 26, 2010</expiration>
<category>Health</category>
<company>Jane Doe's</company>
<deal>Sed ullamcorper sodales luctus. Duis ut lacus at ante malesuada ultrices.</deal>
<extra>Some Extra Info will go here if needed</extra>
<address>123 Some Street, Someplace, World, 12345</address>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
</coupons>
Below is my HTML code. xPath is working at the bottom of the page, but I need it to be sending individual coupon info to the next page/step, not printing on this page.
HTML w/ PHP using SimpleXML to render coupons:
<html>
<head>
<title>Coupons using XML & PHP</title>
<style type="text/css">
#coupon {
width:500px;
fontsize: 93.8%;
margin:0 0 1.5em;
padding:0.5em;
border: dotted 1px #000;
display: block;
list-style:none inside;
background-color:#fff!important;
position:relative;
}
#coupon h5 {width:100%;margin:0;padding:.5em 0;text-align:center;font-size: .75em;border:none;color:#777;}
#coupon h5.watermark {visibility:hidden;display:none;width:0;height:0;}
#coupon h4.exp {font-size:.6em;margin: 1em 0 -.75em 1em;text-align:right;padding: 0.75em;background-color: #fff;border: none;color: #666;-webkit-border-radius: 1em;border:solid 1px #222;position:absolute;left:80%;top:5%;}
#coupon h4 {margin:.5em 0 0 1em;padding:0;color:#777; vertical-align: top;}
#coupon h4 input[type=checkbox] {vertical-align: middle;margin: 0 0 0 1em;}
#coupon h4 em {font-size:.5em;margin:0 0 0 2em;padding:1em 0 0;border-left: solid 1px #888;color:#000;vertical-align:bottom;}
#coupon h1 input[type=submit],
#coupon h1 input[type=button] {padding:.25em;font: normal 900 .75em/1.5 'Arial Black',Helvetica,Arial,sans-serif!important;color:#ccc;padding:.25em 1em;display:block;width:100%;text-align:left;margin:-.5em 0 .5em;
border:solid 1px #000;
-webkit-border-radius: .5em;
box-shadow: 0.3em 0.3em 0.3em #888;-webkit-box-shadow: 0.1em 0.1em 0.1em #888; /* x,y,z coordinages (z is blur/depth) */
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#666), to(#222));
-webkit-transition:all 500ms ease-in;}
#coupon h1 input a {color:#336;font-weight: bold;}
#coupon h1 input[type=submit]:link, #coupon h1 input[type=button]:link {color:#ccc;}
#coupon h1 input[type=submit]:visited, #coupon h1 input[type=button]:visited {color: #888;}
#coupon h1 input[type=submit]:hover, #coupon h1 input[type=button]:hover {color: #000;text-decoration:underline;box-shadow: none;-webkit-box-shadow: none;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#888), to(#ccc));
border:solid 1px #666;}
#coupon h1 input[type=submit]:active, #coupon h1 input[type=button]:active {color:#900;}
#coupon h1#info {font-family: 'Arial Narrow',Helvetica,Arial,sans-serif;color:#fff;padding: .8em 1em;font-size:.8em;line-height:1.75;}
#coupon h2 {display:block;margin:0;padding:0 0 0 1em;font-size:100%;border:none;font-weight: normal;}
address {display:block;margin:0;padding:0;font-size:100%;text-align: center;border:none;}
#coupon h3 {display:block;margin:0;padding:0;font-size:95%;text-align: center;border:none;}
#coupon h6 {display:block;margin:0 auto;padding:0;font-size:85%;text-align: center;border:none;font-weight:light;}
</style>
</head>
<body>
<?php
if (file_exists('coupon.xml')) {
$coupons = simplexml_load_file('coupon.xml');
$CouponNumber = 1; #Defines the html coupons page starting at 1.
foreach($coupons->coupon as $coupon) {
$id = $coupon->attributes()->id;
echo "<form action=\\"+coupon.php\\" method=\\"post\\" name=\\"Single Coupon\\">
<fieldset id=\\"coupon\\">
<input type=\\"hidden\\" value=\\"$id\\" />
<h4 class=\\"exp\\">$coupon->expiration</h4>
<h5 class=\\"watermark\\">KingsportDeals.com | Click to Save, Click to Win!</h5>
<h4>$coupon->category
<em>
<input name=\\"Select\\" type=\\"checkbox\\" value=\\"\\" />
Add Coupon #$CouponNumber to my print que
<em>
</h4>
<h1><input type=\\"submit\\" value=\\"$coupon->company\\" /></h1>
<h2>$coupon->deal</h2>
<h2>$coupon->deal2</h2>
<h2>$coupon->deal3</h2>
<h2>$coupon->deal4</h2>
<h2>$coupon->deal5</h2>
<h5>$coupon->extra</h5>
<address>$coupon->address</address>
<address>$coupon->address2</address>
<address>$coupon->address3</address>
<address>$coupon->address4</address>
<h3><a href=\\"http://$coupon->site \\" target=\\"_blank\\">$coupon->site</a></h3>
<h5>$coupon->phone</h5>
<h6>$coupon->legal</h6>
</fieldset>
</form>";
$CouponNumber++; // increment by 1
}
// this gets the node with the coupon with id = 3
$result = $coupons->xpath("//coupon[@id='3']");
list( , $node) = each($result);
echo $node->attributes()->id;
if(isset($node)) {
echo '<div id=\\"coupon\\">';
echo '<h4 class=\\"exp\\">' . $coupon->expiration . '</h4>';
echo '</div>';
echo "<h4>". $node->category."</h4>";
echo "COM:". $node->company."<br>";
}
} // if (file_exists('coupons.xml'))
?>
</body>
</html>