Forum Moderators: coopster

Message Too Old, No Replies

Submitted form with Smarty assign function

         

toplisek

1:14 pm on May 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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'])){ }

rocknbil

6:02 pm on May 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ID's (and classes) are DOM elements, accessed by client side tools ,such as Javascript or CSS. They are not submitted in forms.

Name attributes in forms are submitted, and are deprecated for use as handles for DOM manipulation client side (that is, for non-form elements, the name attribute can still be accessed client side but why would you want to if you have id's.) A good rule of thumb,

use ID attributes for any Javascript or CSS manipulation (or classes)
Use the the name attributes for your server side scripts.

name="{$name}"....
if (isset( $_POST['name'])){ }

An aside - using "name" as a form field name is bound to get confusing, even if it's a person's name because all form fields have a name attribute. Use family_name, surname, full_name, fname, lname, etc. instead.

$smarty->assign('family_name', $name);

if (isset( $_POST['family_name'])){ }

toplisek

7:39 pm on May 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you for your detailed explanation.
So, if I understand.

1. Assign function will recognize variable inside template
$smarty->assign('name', $family_name);

2. Name attributes in forms are submitted and ID's (and classes) are DOM elements and $family_name will be submitted after button is clicked.
<form id="form1" action="myhandler.php" method="post">
<p>
<label class="myclasstext1">Family name</label>
<input name="{$family_name}" size="50" maxlength="60" class="required" />
</p>

Issue: ID is needed as class is used by jQuery validation V 1.7. See class="required"

3. Then I can access it like this on the PHP side and send message:

$familiy_name= $_POST['familiy_name'];
if (isset( $_POST['family_name'])){ }

Issue: 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?

Notice: Form is redirected to confirmed page not to the same page.

rocknbil

5:57 pm on May 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, I didn't mean to remove the id - leave that in your form - but in PHP, you'd look for "family_name" via the name in the form. Not sure how to answer the second one.