Jump to content

help with radio button


Lassie

Recommended Posts

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;
                 ?> &nbsp

                <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
                }
          }

Link to comment
Share on other sites

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();
    }

Link to comment
Share on other sites

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;
                 ?> &nbsp

                <ul><li class="demo-menu-link"><a href="?page=submenu7&coverID=$coverID">Finnished Cover</a></li></ul><?php
                exit();
            }
            else{
                echo "not Submitted";
            }

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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
                }

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.