SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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']);

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.
    Code:
    <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 Code:
    <?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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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'])){ }

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    SORRY!

    Your template should be:
    Code:
    <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.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?
    PHP Code:
    $smarty->assign('varname''toplisek'); 

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Put them in the same file if you want.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    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?

  10. #10
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •