How to store values of form with Smarty framework?

This assign is to set form display.

I like to know how to set values from inputs into message (mail script).

I have the following:
<p>
<label class=“input1”>Familiy name</label>
<input id=“text1” name=“{$varname}” size=“60” maxlength=“60” class=“required” />
</p>

and assigned:
$smarty->assign(‘varname’, $_POST[‘varname’]);

Your template must contain a valid html form, and your text box is an element of that form. The Action of the form dictates where the vars are sent to.


<form action = "myhandler.php" method="post">
<p>
<label class="input1" for="text1">Familiy name</label>
<input id="text1" name="{$varname}" size="60" maxlength="60" class="required" />
</p>
<input type=submit />
</form>

myhandler.php


<?php

if ( isset( $_POST['text1'])){

echo "now send an email with the message " . $_POST['text1'];

}

?>

warning there are no security checks shown in this code for brevity, nor filtering nor escaping - just to explain the basic principle.

You will need to check that both files are in the same directory for this to work as shown.

I trust this is what you meant by your question.

I’m not sure but I passed variables to templates:
$smarty->assign(‘name’, $name);

Form is submitted

<form id=“form1” action=“myhandler.php” method=“post”>

<p>
<label class=“myclasstext1” for=“text1”>Familiy name</label>
<input id=“text1” name=“{$name}” size=“50” maxlength=“60” class=“required” />
</p>

<input type=“submit” name=“form1” value=“Send” class=“SEND” />

How to pass variables from name=“{$name}” to my variables in PHP to be recognised?

Is this issue with my above code or is it missing some line in Smarty?

Handler PHP:
if (isset( $_POST[‘text1’])){ }

SORRY!

Your template should be:


<form action = "myhandler.php" method="post">
<p>
<label class="input1" for="text1">Familiy name</label>
<input id="text1" name="text1" value="{name}" size="60" maxlength="60" class="required" />
</p>
<input type=submit />
</form>

Try that.

Should be this content inside Confirmation web page myhandler.html(and its controller file(myhandler.php is controller of Confirmed web page)
OR inside controller PHP for Smarty where is form?

Form is on different page than confirmation page…

I don’t know because you are not showing all the code.

Try a real value first, make sure this appears in your code before you go any further, maybe you have not wired up Smarty correctly?


$smarty->assign('varname', 'toplisek');

If Smarty is correct wired up where to put IF sentence?
Inside handler.php (action file) or basic file where is form and its controller?

Put them in the same file if you want.

You are right. Thank you. Even if I put fixed values (without forms values) it will not be shown values inside message and even echo will be empty field.

What can be else issue in this form?
Are variables not assigned to tpl?
Are variables assigned in wrong way in controller?
Are there ID (needed for validation) which block submitted form values?
Is this issue in action handler?

This is getting awfully mixed up, I am sorry but I do not appear to be helping you much. Why don’t you start here again in the docs.

Your template should be in the correctly designated smarty /templates folder, try and copy/paste code from the documentation above until you get this worked out.