adrianmak Posted May 3, 2015 Share Posted May 3, 2015 order template <?php $id = $input->urlSegment1; $out = ""; $out .= "{$pages->get($id)->title}<br/>"; $out .= "{$pages->get($id)->body}<br/>"; $out .= "PRICE: {$pages->get($id)->discount_price}<br/>"; $out .= " <form action='{$config->urls->root}checkout' method='post'> <input type='text' name='product' value='{$pages->get($id)->title}'> <input type='text' name='price' value='{$pages->get($id)->discount_price}'> <input type='submit' value='Pay'> </form> "; $page->body = $out; include('./main.php'); ?> checkout template <?php $out = ''; $out .= $input->post->product; $out .= $input->post->price; $out .= "Submitted data"; $page->body .= $out; include('./main.php'); When order is submitted to checkout page, no post values are got. Anything wrong with my code ? ps I'm testing on 2.5.3 Link to comment Share on other sites More sharing options...
tpr Posted May 3, 2015 Share Posted May 3, 2015 action='{$config->urls->root}checkout' Isn't your checkout page end with a slash? (yoursite.com/checkout/) If so, you may have a redirect so post values are lost (checkout -> checkout/), so you need to append a slash to the form action. Check it on the Dev Tools/Firebug Network tab. 2 Link to comment Share on other sites More sharing options...
Wanze Posted May 3, 2015 Share Posted May 3, 2015 Yep the problem is the one tpr describes. Beside that, you should consider the following: Don't build your urls manually, let ProcessWire do it for you: $action = $pages->get('/checkout/')->url; <form action="$action"> Sanitize input $id = (int) $input->urlSegment1; // Must be an integer Cache the page you're searching; I'm sure that ProcessWire also returns a cached page, but in theory, each $pages->get() call fires an SQL query: $myPage = $pages->get($id); // Assign the found page to variable $myPage if ($myPage->id) { // Make sure we found a page echo $myPage->title; } Escape output $title = $sanitizer->entities($myPage->title); echo "<input type='text' name='product' value='{$title}'>"; Edit: This is only needed if your title field does not have the "HTML Entitiy Decoder" textformatter applied. Cheers 8 Link to comment Share on other sites More sharing options...
adrianmak Posted May 4, 2015 Author Share Posted May 4, 2015 As tpr pointed out, an ending slash is required. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now