SalsaScript Tutorial (1, 2, 3, 4, 5)

Part IV - Putting it All Together

We have so far created a package, created a form to add news items, and listed all of the news items in the database. Now we're going to combine those two sections onto one page.

<?
var conditions = new Array();
var objs=salsa.getObjects("news_item",conditions); 
if (objs.length > 0) {
	print('<ul>');
	for each (salsa_entry in objs){
		print('<div id="row_entry" style="clear: all; width: 14em;">\n');
		print('\t<li><strong>' + salsa_entry.Name_or_Headline + '</strong></li>');
		print('\t<li><i>' + salsa_entry.Short_Description + '</i></li>');
		print('</div>');
	}
	print('</ul>');
} else {
	print('No Entries Found');
}
?>

<form action="/save" method="POST">
	<input type="hidden" name="table" value="news_item"/>
	<input type="hidden" name="key" value=""/>
	<label for="Name_or_Headline">Name of Article</label><br/>
	<input type="text" name="Name_or_Headline"><br/>
	
	<label for="Short_Description">Description</label><br/>
</form>

Adding news items in the form should then immediately appear in the list above the form.