Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

$_POST help

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
cybernet
Smarty Rookie


Joined: 29 Sep 2011
Posts: 6

PostPosted: Tue Oct 04, 2011 9:06 pm    Post subject: $_POST help Reply with quote

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 ? Very Happy

i have even tried in a template
Code:
{if !isset($_POST['title']) }
   die?
{/if}
Back to top
View user's profile Send private message
cybernet
Smarty Rookie


Joined: 29 Sep 2011
Posts: 6

PostPosted: Thu Oct 06, 2011 4:31 am    Post subject: Reply with quote

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 ? Shocked
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 06, 2011 1:43 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cybernet
Smarty Rookie


Joined: 29 Sep 2011
Posts: 6

PostPosted: Fri Oct 07, 2011 12:33 pm    Post subject: Reply with quote

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 Cool
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 07, 2011 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cybernet
Smarty Rookie


Joined: 29 Sep 2011
Posts: 6

PostPosted: Sun Oct 09, 2011 9:21 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Oct 09, 2011 9:34 am    Post subject: Reply with quote

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
View user's profile Send private message
cybernet
Smarty Rookie


Joined: 29 Sep 2011
Posts: 6

PostPosted: Sun Oct 09, 2011 9:50 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Oct 09, 2011 1:28 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP