Categories > TinyButStrong general >

Processing Forms.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Matt
Date: 2007-01-04
Time: 13:58

Processing Forms.

Hi,
   My name is Matt and just downloaded tbs today and I'm already impressed by what it can do. I have started to recode my site with this new templating engine as it's made my life easier than before.

Now. I'm currently coding my administrator panel and have come across a problem. Here is my html code

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../templates/default/index.css" />
        <title>[var.sitename]</title>
    </head>
<body>
    <div id="header"><h1>[var.sitename]</h1><h5>[var.siteslogan]</h5></div>
    <div id="navigation"><a href="#">Google</a></div>
    <div id="content">
        <h5>Welcome to the Admin Panel</h5>
        <p>Hello and welcome to the administrator panel of your newly installed website. Here you will find all the options you need
        to configure your site correctly.</p>
        <h5>General Configuration</h5><br/>
        <form action="index.php" method="post">
        <table width="100%">
        <tr><td>Site Url (Required)</td><td><input type="text" name="siteurl"></td></tr>
        <tr><td>Site Name (Required)</td><td><input type="text" name="sitename"></td></tr>
        <tr><td>Site Slogan (Required)</td><td><input type="text" name="siteslogan"></td></tr>
        <tr><td>Site Footer (Required)</td><td><textarea name="sitefooter" rows="5"></textarea></td></tr>
        <tr><td>Email Activation</td><td><input type="radio" name="eactivate" value="1">Yes<input type="radio" name="eactivate" value="0">No</td></tr>
        <tr><td><input type="submit" value="Submit" class="button"></td></tr>
        </table>
        </form>
    </div>
    <div id="footer">[var.sitefooter]</div>

</body>
</html>

And here is my php code.

<?php

include_once("../tbs_class.php");
include_once("../config.php");

$sitename   =  "Site Title";
$siteslogan =  "Site Slogan";
$sitefooter =  "Site Footer";

$tbs = new clsTinyButStrong ;
$tbs->LoadTemplate("../templates/default/admin/index.html");


$tbs->Show();

?>


Now, when I submit the html form I want the data to be processed and put into the Mysql database. The thing is, I'm not sure how to go about it.

Because when I do this : $sitename   =  $_post['value'];

It makes tbs put an error out. Any help is much appreciated.

So all I want to do is retreive the form data, put it into the database, then for tbs to get the values from the database and show them. Or if you can find a better way ...

Regards,
-Matt
By: Scythe
Date: 2007-01-04
Time: 15:04

Re: Processing Forms.

Well, what's the error it gives you?

I believe TBS shouldn't affect how your forms submissions work, however we can better help you if we know what error you get. 

Also, typically when you retrieve a value you want to check if isset() first.  That way you prevent a null from occurring. Then, on storage via a query you want to escape() the input to prevent mySQL injections.

Anyway, let us know the error :D
By: Matt
Date: 2007-01-04
Time: 15:12

Re: Processing Forms.

Yeah, I think it was a null value which was giving me an error. When the form was submitted, the error went away.

Using the isset function worked for me.

Thanks

Regards,
-Matt
By: Matt
Date: 2007-01-04
Time: 19:53

Re: Processing Forms.

I actually have another problem now and that is when re-visitng the admin page.

Once on the page I can change the websitename etc. The form will work fine.

When leaving the page then visiting later on, the values will delete themselves.

Here is my current php code

<?php
include_once("../tbs_class.php");
include_once("../config.php");
$tbs = new clsTinyButStrong ;
$tbs->LoadTemplate("../templates/default/admin/index.html");
$sitename = $_POST['sitename'];
$sitslogan = $_POST['siteslogan'];
$sitefooter = $_POST['sitefooter'];
$update = "UPDATE config SET sitename='$sitename', siteslogan='$siteslogan', sitefooter='$sitefooter'";
$result=mysql_query($update);
$tbs->MergeBlock('config',$connect,'SELECT * FROM config') ;
mysql_close($connect);
$tbs->Show();
?>

Any help appreciated, also, you can contact me via Aim : Popcorned23 or msn : webmaster@neowin.fh-net.com
By: sheepy
Date: 2007-01-06
Time: 09:51

Re: Processing Forms.

If the about code not only handles update but also handles display of the page, then it seems to me then everytime you visit the page, it does an update.

And when you just visit it (instead of form posting to it), ir receives no form data, no $_POST.  So it'll faithfully updates the config with empty data.

I'll suggest you turn on display_error and set error level to E_ALL, so that you'll know when it can't find an index in an array.  I even go as far as installing xdebug, which shows a nice, scary stack trace on every error, forcing me to deal with it.