Quote:
|
Originally Posted by sde
Hi Saul,
With PHP, you don't really have to check if the variable is set. If it is not, it will just echo nothing. PHP is not as strict as other languages.
The quickest way to write the code above would be like this:
PHP Code:
User ID: <input type="text" name="user_id" size="20" tabindex="2"
maxlength="127" value="<?=$Mydata['user_id']?>">
<?=$somevar?> is a shortcut in php to print the variable.
As for your 'note', .. it really doesn't matter if there are elements in the html form that don't exist in the PHP. Think of PHP as a tool to generate text.
this question threw me off a bit. The following questions don't really make sense to me too. Maybe I can explain it like this.
PHP executes on the server-side, Javascript executes in the browser on the client side. So does HTML. So, by the time you see HTML on the web page, PHP is done processing it. You're just using PHP to generate text.
Hope that helps somewhat.
|
Thanks for the reply! I like the shortcuts you suggest...you'r right that you do not need the isset each time, altough every time I use an undefined variable it gets logged as a warning in my error log.
Actually, the real difficuly is when we try to avoid hardcoding this in the form altogether...e.g. given an arbirary form and an arbitrary array (index using the form names), can we populate the form...its easy to get form data into PHP but not the other way (as you say in your last comment). I'm working on a workaround for this....generating javascript..roughly speaking its:
<?php
print "<script language=\"javascript\">";
print "function formdata() {";
foreach ($myArray as $name => $value)
print "this.$name = $value;";
print "}";
print "function loadform() {";
print "formdata myFormData;";
print "for (form_element in document.forms[0])"
document.form[0].form_element = myFormData.form_element;
print "}"
print "</Javascript>";
then you can have and onload statement or something. But the problem here is that the javascript statement:
document.form[0].form_element = myFormData.form_element;
does not do what we wnt it to do (populate name/value pairs in the form)...I'm trying to figure out something for this. If you have any ideas, let me know!
Thanks!
Saul.