• I am beginning to learn php and mysql for web development. I want to use it with wordpress and I am falling at the first hurdle. I created an orderform.php and added it in to the theme files and amended the index.php file so that it would ‘pick up’ the order form but on trying to open my site it said it could not find my order form. Could you direct me to further information on creating forms for wordpress and using with mysql? Many thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Yes, “page templates” is the magic word.

    Peter

    Thread Starter niamh2

    (@niamh2)

    Hi,

    Thank you for replying.
    I’ve been through that several times but it leaves me no further forward. I can write the code or copy it but what I don’t understand is that if I create an order form and have the code to process the order where do I put that file so the two work together. Can I put the order form as part of the theme?

    Regards,

    hi,

    i think you should going through ‘how to make plugin’. For your example it better to make plugin because you can place your order from at anywere.

    cayrol

    You can do that all in one page template.

    The way to go about is to create your form in a page template, also put the code in for processing the form (select by checking whether the form had been submitted or not – basic PHP), create a blank page and assign the page template to it.

    Peter

    Thread Starter niamh2

    (@niamh2)

    Thank you Peter.
    Ok I am still lost. I have this code successfully working in a page:

    <html>
    <head><title>Bob’s Auto Parts</title></head>
    <body>
    <form action=”processorder.php” method=”post”>
    <table border=”0″>
    <tr bgcolor=”#cccccc”>
    <td width=”150″>Item</td>
    <td width=”15″>Quantity</td>
    </tr>
    <tr>
    <td>Tyres</td>
    <td align=”center”><input type=”text” name=”tireqty” size=”3″ />
    </td>
    </tr>
    <tr>
    <td>Oil</td>
    <td align=”center”><input type=”text” name=”oilqty” size=”3″ />
    </td>
    </tr>
    <tr>
    <td>Spark Plugs</td>
    <td align=”center”><input type=”text” name=”sparkqty” size=”3″/>
    </td>
    </tr>
    <tr>
    <td>How did you find Bob’s?</td>
    <td><select name=”find”>
    <option value = “a”>I’m a regular customer</option>
    <option value = “b”>TV advertising</option>
    <option value = “c”>Phone directory</option>
    <option value = “d”>Word of mouth</option>
    </select>
    </td>
    </tr>
    <tr>
    <td colspan=”2″ align=”center”><input type=”submit” value=”Submit Order” /></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    I need to know about the next piece of code, which is the “processorder.php”,as to where I put it. Do I put it somewhere with the file manager or do I put it as part of the theme similar to the php for sidebars? You are suggesting that I put the two together which I tried without success.

    <html>
    <head>
    <title>Bob’s Auto Parts – Order Results</title>
    </head>
    <body>
    <h1>Bob’s Auto Parts</h1>
    <h2>Order Results</h2>
    <?php
    echo ‘<p>Order processed at ‘;
    echo date(‘H:i, jS F’);
    echo ‘</p>’;
    echo ‘<p>Your order is as follows: </p>’;
    echo $tireqty.’ tires
    ‘;
    echo $oilqty.’ bottles of oil
    ‘;
    echo $sparkqty.’ spark plugs
    ‘;

    $totalqty = 0;
    $totalamount = 0.00;

    $totalqty = 0;
    $totalqty = $tireqty + $oilqty + $sparkqty;
    echo ‘Items ordered: ‘.$totalqty.’
    ‘;

    $totalamount = 0.00;

    define(‘TIREPRICE’, 100);
    define(‘OILPRICE’, 10);
    define(‘SPARKPRICE’, 4);

    $totalamount = $tireqty * TIREPRICE
    + $oilqty * OILPRICE
    + $sparkqty * SPARKPRICE;

    echo ‘Subtotal: $’.number_format($totalamount,2).’
    ‘;

    $taxrate = 0.10; // local sales tax is 10%
    $totalamount = $totalamount * (1 + $taxrate);
    echo ‘Total including tax: $’.number_format($totalamount,2).’
    ‘;

    ?>
    </body>
    </html>

    If I could get this going then I could work through my book on PHP, MuySQL using WP without having to set up some complicated testbed.

    Thank you in advance for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating forms and adding to the theme’ is closed to new replies.