Categories > TinyButStrong general >

How to display blank input fields if there is no data

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Don Bledsoe
Date: 2007-05-24
Time: 00:23

How to display blank input fields if there is no data

I want to have an ADD record form that comes up blank the first time, but keeps the data from the last record after the submit button is clicked.

Right now, when the form is opened, there's no data to use in the VALUE="" argument of the INPUT statement, so it shows the merge code:
<input name="FirstName" id="FirstName" type="text" size=20 maxlength=20 value="[blk4.custFname]">
Is there a way to blank out the [blk4.custFname] when there is no data to display?
By: Skrol29
Date: 2007-05-24
Time: 01:45

Re: How to display blank input fields if there is no data

hi,

The more simple way is to add a section "nodata" to your block. This nodata section should be exactly the same as the normal section, but with blanks instead of TBS fields.
By: Don Bledsoe
Date: 2007-05-24
Time: 03:32

Re: How to display blank input fields if there is no data

I think I missed something.

The "block" is about 10 rows down the page, so I don't know the best way to define the beginning and end row of each block. Do you have a recommendation?
By: Skrol29
Date: 2007-05-24
Time: 11:51

Re: How to display blank input fields if there is no data

Hi,

I don't get it. Your block is 10 rows height in design mode, or they are 10 rows when merged ?
If it is 10 rows height in design mode, then you can define it with "block=tr+tr+tr+tr+...".
A bit long, but it works.

Another way for your problem is to create an empty record at the PHP side when there is no records.
Example:
$data = ... // get the records here
if 'count($data)==0) $data = array('id'=>'', 'name'=>'',... ); // empty record
$TBS->MergeBlock('blk4',$data);
By: Don Bledsoe
Date: 2007-05-24
Time: 12:37

Re: How to display blank input fields if there is no data

I am not being clear.

o This is an input form to add a record to the database.
o It is initially displayed with blank fields to enter data.
o On submit, the record is inserted.
o Following the insert statement, I call a MergeBlock:
    $Db->Execute('INSERT INTO domains ....);
$TBS->LoadTemplate('tpl/add.tpl.html');
$TBS->MergeBlock('blk4','tbssql','SELECT * FROM domains WHERE id=LAST_INSERT_ID()');
$TBS->Show();
This should re-display the inserted record. I can edit changed data for the next record and submit and insert again, and again and again.

You said I needed to duplicate the blocks and the easy way seemed to be to duplicate the table and TBS will use one table or the other table. What is happening is that both tables are being displayed, so I am not doing this right. I tried to use [blk4.field1;block=tr+tr+tr+tr+tr+tr+tr+tr+tr] but it didn't work, so I'm not doing something right. Here's the form:
    <form name="domainadd" action="add.php" method="POST">
<table class="format">
<tr><td class=formlabel>First Name&nbsp;</td><td align="left"><input name="FirstName" id="FirstName" type="text" size=20 maxlength=20 value="[blk4.custFname;block=tr+table]"></td></tr>
<tr><td class=formlabel>Last Name&nbsp;</td><td align="left"><input name="LastName" id="LastName" type="text" size=20 maxlength=20 value="[blk4.custLname]"></td></tr>
<tr><td class=formlabel>Company&nbsp;</td><td align="left"><input name="Company" id="Company" type="text" size=40 maxlength=40 value="[blk4.company]"></td></tr>
<tr><td class=formlabel>Email&nbsp;</td><td align="left"><input name="Email" id="Email" type="text" size=45 maxlength=45 value="[blk4.email]"></td></tr>
<tr><td class=formlabel>Account&nbsp;</td><td align="left"><input name="Account" id="Account" type="text" size=8 maxlength=8 value="[blk4.account]"></td></tr>
<tr><td class=formlabel>Domain Name&nbsp;</td><td align="left"><input name="DomainName" id="DomainName" type="text" size=68 maxlength=68 value="[blk4.domain]"></td></tr>
<tr><td class=formlabel>Domain Created on&nbsp;</td><td align="left"><input name="DomainCreated" id="DomainCreated" type="text" size=10 maxlength=10 value="[blk4.createdate]"></td></tr>
<tr><td class=formlabel>Domain Expires on&nbsp;</td><td align="left"><input name="DomainExpires" id="DomainExpires" type="text" size=10 maxlength=10 value="[blk4.expiresdate]"></td></tr>
<tr><td class=formlabel>Name Servers at&nbsp;</td><td align="left"><input name="Hosted" id="Hosted" type="text" size=1 maxlength=1 value="[blk4.hosted]"></td></tr>
<tr height=50><td> </td><td align="left"><input name="submit" id="submit" type="submit" value="  ADD  "></td></tr>
</table>

<table class="format">
<tr><td class=formlabel>First Name&nbsp;</td><td align="left"><input class=addrecord name="FirstName" id="FirstName" type="text" size=20 maxlength=20 value=""></td></tr>
<tr><td class=formlabel>Last Name&nbsp;</td><td align="left"><input class=addrecord name="LastName" id="LastName" type="text" size=20 maxlength=20 value=""></td></tr>
<tr><td class=formlabel>Company&nbsp;</td><td align="left"><input class=addrecord name="Company" id="Company" type="text" size=40 maxlength=40 value=""></td></tr>
<tr><td class=formlabel>Email&nbsp;</td><td align="left"><input class=addrecord name="Email" id="Email" type="text" size=45 maxlength=45 value=""></td></tr>
<tr><td class=formlabel>Account&nbsp;</td><td align="left"><input class=addrecord name="Account" id="Account" type="text" size=8 maxlength=8 value=""></td></tr>
<tr><td class=formlabel>Domain Name&nbsp;</td><td align="left"><input class=addrecord name="DomainName" id="DomainName" type="text" size=68 maxlength=68 value=""></td></tr>
<tr><td class=formlabel>Domain Created on&nbsp;</td><td align="left"><input class=addrecord name="DomainCreated" id="DomainCreated" type="text" size=10 maxlength=10 value=""></td></tr>
<tr><td class=formlabel>Domain Expires on&nbsp;</td><td align="left"><input class=addrecord name="DomainExpires" id="DomainExpires" type="text" size=10 maxlength=10 value=""></td></tr>
<tr><td class=formlabel>Name Servers at&nbsp;</td><td align="left"><input class=addrecord name="Hosted" id="Hosted" type="text" size=1 maxlength=1 value=""></td></tr>
<tr height=50><td> </td><td align="left"><input name="submit" id="submit" type="submit" value="  ADD  "></td></tr>
</table>
</form>
I tried block=tr+table, but I'm not doing something right with that.

I greatly appreciate your patience in helping me to understand this.
By: Skrol29
Date: 2007-05-24
Time: 17:19

Re: How to display blank input fields if there is no data

Hi,

I understand now. It is not not what I thougth first.


There is a very simple way I think. Just let you TBS fields for block "blk4" but take of all parameter "block=..." about it.
When MergeBlock() doesn't found the bounds of a block to merge, the it merges all fields with the first record only.
This is very relevant with your case because you need to merge "blk4" with only one record or none.

At the PHP side, it could something like this:
$TBS->LoadTemplate('tpl/add.tpl.html');
if ($insert) {
  $Db->Execute('INSERT INTO domains ....);
  $TBS->MergeBlock('blk4','tbssql','SELECT * FROM domains WHERE id=LAST_INSERT_ID()');
} else {
  $TBS->MergeBlock('blk4','clear');
}
$TBS->Show();

By: Don Bledsoe
Date: 2007-05-25
Time: 16:51

Re: How to display blank input fields if there is no data

This works perfectly! Thank you!

I also added a custom variable to indicate "ADD RECORD" or "EDIT + ADD RECORD" title on the page. I had to do this because it's so fast, users were wondering if the record was actually added or not, so this gives a visual indication that the record was added and they can edit the fields and add another, similar record.