Lassie Posted March 5, 2011 Share Posted March 5, 2011 I have a function to display some images and allow a user to select a choice via a radio button.The value is then passed to another function. I have 2 problems My selection is not being passed back and I cant assign the value to a query sring in a link to another page. On the form do i need to add checked? Any help appreciated. function cover() { echo'<h2>Please upload your book cover or choose one from the selection</h2> <p>All book ideas require a cover. Your choice can be changed at a later date.</p>'; //process selection of cover if (isset($_POST['submit'])) { $coverID=$_POST['cover']; echo $coverID; ?>   <ul><li class="demo-menu-link"><a href="?page=submenu7&coverID=$coverID">Finnished Cover</a></li></ul><?php exit(); } else{ echo "not Submitted"; } global $wpdb; $query = "select * from wp_cover"; $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result){ return false; } echo'<div class="wrap"><p>choose from one of the covers below</p></div>'; ?><form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" id="cover" enctype="multipart/form-data"> <table><tr><?php /* display picture and radio button */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $coverID=$row['coverID']; echo"<img src=\"/wordpress_3/wp-content/plugins/Authors2/jackets/{$row['pix']}\" />"; echo"<td>"; echo $coverID; echo "<Input type = 'Radio' Name ='cover' value= '$coverID'/>"; ?> </tr></table> <input type=submit value=submit> </form><?php } } Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 5, 2011 Author Share Posted March 5, 2011 I have now got the form to submit with a vale but I can only get one button(out of a test of 3) to work. Just to emblish this post the link goes to the following code. The idea is to pass the cover id to the finished cover function which will display the selected cover with other data. The $_GET['coverID'] just gives me $coverID. not the ID value which is numeric. //output page content for each plugin submenu page if ($_GET['page']== "submenu7"){ $cover=$_GET['coverID']; echo $_GET['coverID']; FinnishedCover($cover); }elseif($_GET['page'] == "submenu6") { AuthorRegistration_page(); } elseif ($_GET['page'] == "submenu5") { cover(); } elseif ($_GET['page'] == "submenu4") { Upload_page(); } elseif ($_GET['page'] == "submenu3") { Marketing_page(); } elseif ($_GET['page'] == "submenu2") { Synopsis_page(); } else { //page 1 is default General_page(); } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 5, 2011 Share Posted March 5, 2011 Sounds like you've enclosed a variable in a single quoted string. Post the code that generates that part of the form. Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 5, 2011 Author Share Posted March 5, 2011 Hi Thanks This is the code echo $coverID gives the correct value(although only one radio button works but that is not passed in the link. //process selection of cover if (isset($_POST['cover'])) { $coverID=$_POST['cover']; echo $coverID; ?>   <ul><li class="demo-menu-link"><a href="?page=submenu7&coverID=$coverID">Finnished Cover</a></li></ul><?php exit(); } else{ echo "not Submitted"; } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 5, 2011 Share Posted March 5, 2011 You aren't even within <?php ?> tags where that variable is, so there's no way it will echo the value of it. Didn't you say in the OP that the problem was with a radio button? That code doesn't produce one . . . <ul><li class="demo-menu-link"><a href="?page=submenu7&coverID=<?php echo urlencode($coverID); ?>">Finished Cover</a></li></ul> Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 5, 2011 Author Share Posted March 5, 2011 Hi Thanks. Yes i have just discovered that and it now works. I still cant get the buttons to work though. Only the first one works. ?><form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" id="cover" enctype="multipart/form-data"> <table width="700"><tr><?php /* display picture and radio button */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $coverID=$row['coverID']; echo"<img src=\"/wordpress_3/wp-content/plugins/Authors2/jackets/{$row['pix']}\" />"; echo"<td>"; echo "<input type = 'radio' name ='cover' value= '$coverID'/>"; ?> <input type="submit" value="submit"> </tr></table> </form><?php } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 5, 2011 Share Posted March 5, 2011 Can you explain what about it doesn't work, please? Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 6, 2011 Author Share Posted March 6, 2011 Sorry. Only one button is active.Three images show each with a radio button and a submit button, but only the first one will process the form whem the radio button is checked and the submit button pressed. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 Post the result of a View--->Source that includes the html markup for the form. Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 7, 2011 Author Share Posted March 7, 2011 Ok Here is the relevant part. <ul id="demo-menu"> <li class="demo-menu-link"><a href="?page=submenu6">Author Registration</a></li> <li class="demo-menu-link"><a href="?page=submenu5">Cover</a></li> <li class="demo-menu-link"><a href="?page=submenu4">Upload</a></li> <li class="demo-menu-link"><a href="?page=submenu3">Marketing</a></li> <li class="demo-menu-link"><a href="?page=submenu2">Book Idea</a></li> <li class="demo-menu-link"><a href="?page=Authors2.php">General</a></li> </ul> <div style="clear:right;"></div> <div class="wrap"> <div id="icon-plugins" class="icon32"></div> <h2>Authors Register and Upload your book idea</h2> <h4>These pages allow you to add additional information to support your book idea or synopsis.<br /> Please register your information in the following order.....</h4> <hr/> <h2>Please upload your book cover or choose one from the selection</h2> <p>All book ideas require a cover. Your choice can be changed at a later date.</p>not Submitted<div class="wrap"><p>choose from one of the covers below</p></div><form action="" method="POST" id="cover" enctype="multipart/form-data"> <table width="700"><tr><img src="/wordpress_3/wp-content/plugins/Authors2/jackets/old_cover.png" /><td><input type = 'radio' name ='cover' value= '1'/> <input type="submit" value="submit"> </tr></table> </form><img src="/wordpress_3/wp-content/plugins/Authors2/jackets/blue_cover.png" /><td><input type = 'radio' name ='cover' value= '2'/> <input type="submit" value="submit"> </tr></table> </form><img src="/wordpress_3/wp-content/plugins/Authors2/jackets/GDL2.png" /><td><input type = 'radio' name ='cover' value= '3'/> <input type="submit" value="submit"> </tr></table> </form> Quote Link to comment Share on other sites More sharing options...
Lassie Posted March 7, 2011 Author Share Posted March 7, 2011 Ok I have found the error.It was in the the form.I needed to close the form otside of the while loop. Thank you everyone. ?><form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" id="cover" enctype="multipart/form-data"> <table width="700"><tr><?php /* display picture and radio button */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $coverID=$row['coverID']; echo"<img src=\"/wordpress_3/wp-content/plugins/Authors2/jackets/{$row['pix']}\" />"; echo"<td>"; echo "<input type = 'radio' name ='cover' value= '$coverID'/>"; ?> <input type="submit" value="submit"> <?php echo"</td>"; } ?></tr></table> </form><?php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.