View previous topic :: View next topic |
Author |
Message |
cybernet Smarty Rookie
Joined: 29 Sep 2011 Posts: 6
|
Posted: Tue Oct 04, 2011 9:06 pm Post subject: $_POST help |
|
|
Code: | $postlist = new Smarty;
...
case 'submit':
foreach(explode(":","desc:title") as $v) {
if (!isset($_POST[$v]))
$postlist->display('no_posted_data.tpl');
}
|
post.tpl
Code: |
<form action="post.php?action=submit" method="post">
<legend>..title..</legend>
<table border="1">
<tr>
<td>{$post_form.title}:</td>
<td>
<input type="text" name="title" size="40">
</td>
</tr>
<tr>
<td valign="top">{$post_form.desc}:</td>
<td><textarea name="desc" cols="80" rows="10"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
|
the only problem is that if i submit the form empty is still get processed
any help please ?
i have even tried in a template
Code: | {if !isset($_POST['title']) }
die?
{/if}
|
|
|
Back to top |
|
cybernet Smarty Rookie
Joined: 29 Sep 2011 Posts: 6
|
Posted: Thu Oct 06, 2011 4:31 am Post subject: |
|
|
is this site only for questions but not for answers ?
this is the second question i got but no one answers
are there any project active coders on this forum ? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 06, 2011 1:43 pm Post subject: |
|
|
From inside the template, post vars are available as $smarty.post.foo, or assign them yourself. Is that what you needed? As for the form getting processed when empty, that needs to be handled in your PHP code, and it doesn't appear that you included those parts in your snippets. |
|
Back to top |
|
cybernet Smarty Rookie
Joined: 29 Sep 2011 Posts: 6
|
Posted: Fri Oct 07, 2011 12:33 pm Post subject: |
|
|
complete content of post.php
Code: | <?php
require('../dev0_inc/smarty/Smarty.class.php');
require('../dev0_inc/config/ride_mysql.php');
$postlist = new Smarty;
$postlist->error_reporting = E_ALL & ~E_NOTICE;
$postlist->debugging = false;
$postlist->caching = true;
$postlist->cache_lifetime = 30;
// setConfig for *.conf files
$postlist->setConfigDir('../dev0_inc/config');
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
switch($_action) {
case 'add':
$postlist->display('post.tpl');
break;
case 'submit':
foreach(explode(":","desc:title") as $v) {
if (!isset($_POST[$v]))
$postlist->display('no_posted_data.tpl');
}
$completed_title = $_POST['title'];
$completed_desc = $_POST['desc'];
$insert = mysql_query("private") or die($postlist->display('mysql_died.tpl'));
$postlist->display('post_submit.tpl');
break;
case 'view':
default:
// $form[''] = '';
$form['title'] = 'Post TiTLe';
$form['desc'] = 'Description';
$postlist->assign('post_form', $form);
$postlist->display('post.tpl');
break;
}
?> |
complete post.tpl
Code: | {include 'header.tpl' cache_lifetime=60}
{include 'cyber_top.tpl' cache_lifetime=60}
<div id="content">
<br /><br /><br /><br />
<form action="post.php?action=submit" method="post">
<legend>aDD` your desire</legend>
<table border="1">
<tr>
<td>{$post_form.title}:</td>
<td>
<input type="text" name="title" size="40">
</td>
</tr>
<tr>
<td valign="top">{$post_form.desc}:</td>
<td><textarea name="desc" cols="80" rows="10"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</div>
{* include 'footer_menu.tpl' cache_lifetime=60 *}
{include 'footer.tpl' cache_lifetime=60} |
on the others post_*.tpl are just text messages
so i should use
if (!isset($smarty.post.$v))
instead of
if (!isset($_POST[$v]))
??
thanks in advance
and could you just look over the hole script and see if something is wrong ? or should be fixed |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Oct 07, 2011 1:55 pm Post subject: |
|
|
use $_POST in PHP and {$smarty.post} in the template (or assign it yourself)
I usually use if !empty($_POST) in PHP to test if a form has been submitted. I would also recommend turning off caching until the form works ok, then enable caching and test if things still work as expected. I normally do not cache pages with forms that get repopulated anyways. |
|
Back to top |
|
cybernet Smarty Rookie
Joined: 29 Sep 2011 Posts: 6
|
Posted: Sun Oct 09, 2011 9:21 am Post subject: |
|
|
dude please help me
still not working
i'm using the latest smarty 3.1.3
this are my final modifications
Code: | <?php
require('../dev0_inc/smarty/Smarty.class.php');
require('../dev0_inc/config/ride_mysql.php');
$postlist = new Smarty;
$postlist->error_reporting = E_ALL & ~E_NOTICE;
$postlist->debugging = false;
$postlist->caching = false;
$postlist->cache_lifetime = 30;
// setConfig for *.conf files
$postlist->setConfigDir('../dev0_inc/config');
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
switch($_action) {
case 'add':
// adding a new entry form
$postlist->display('post.tpl');
break;
case 'submit':
foreach(explode(":","desc:title") as $v) {
if (!isset($_POST[$v]))
$postlist->display('no_posted_data.tpl');
}
$completed_title = $_POST['title'];
$completed_desc = $_POST['desc'];
$insert = mysql_query("prv") or die($postlist->display('mysql_died.tpl'));
// submitting a new entry
$postlist->display('post_submit.tpl');
break;
case 'view':
default:
// $form[''] = '';
$form['title'] = 'Post TiTLe';
$form['desc'] = 'Description';
$postlist->assign('post_form', $form);
$postlist->display('post.tpl');
break;
}
?> |
post_submit.tpl
Code: | {include 'header.tpl' cache_lifetime=60}
{include 'cyber_top.tpl' cache_lifetime=60}
<div id="content">
<br /><br /><br /><br />
{if !isset($postlist.post.title) }
die?
{/if}
<b>if you're seeing this it means you made it LoL</b>
{include 'footer_menu.tpl' cache_lifetime=60}
{include 'footer.tpl' cache_lifetime=60} |
when i submit the form, either empty or filled i get the hole content of post_submit.tpl
is like {if !isset($postlist.post.title) } was never there
and how do i insert in mysql characters like Ț, ț / Ţ, ţ
mysql tables are utf8 and in the view form i use escape:'htmlall':'UTF-8'
i wanna store posts in mysql just like phpbb
take a look
http://img268.imageshack.us/img268/5525/96844860.png
Last edited by cybernet on Sun Oct 09, 2011 9:43 am; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Oct 09, 2011 9:34 am Post subject: |
|
|
Special Smarty variables in templates start always with $smarty not with the PHP varibale name of the Smarty object.
Code: | {if !isset($smarty.post.title) }
die?
{/if} |
|
|
Back to top |
|
cybernet Smarty Rookie
Joined: 29 Sep 2011 Posts: 6
|
Posted: Sun Oct 09, 2011 9:50 am Post subject: |
|
|
U.Tews wrote: | Special Smarty variables in templates start always with $smarty not with the PHP varibale name of the Smarty object.
Code: | {if !isset($smarty.post.title) }
die?
{/if} |
|
thanks
but in both cases die? doesn't appear ( empty form or filled )
i wanna store posts in mysql just like phpbb
take a look
http://img268.imageshack.us/img268/5525/96844860.png
can you give an example of post script ?
i can use that as reference |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Oct 09, 2011 1:28 pm Post subject: |
|
|
There is a guestbook app for an example:
http://www.smarty.net/sampleapp1
Also google "smarty mysql example", brings up some useful things. |
|
Back to top |
|
|