Hello,
how about this?
<input type = "text" name="make" value="<?php echo htmlspecialchars($make) ; ?>">
in a textfield you should not use ,
if the user add to the field ' " \ or other special characters, they will kill your html code, that's why you need to use a function to change them into quoted characters.
-form to hold the data input by the user?-
i use functions to make form elements , and rewrite the posted values.
Its not useful if you need one or two fields, but useful if you make about 10+ 🙂
You can combine the required fields as you wish. It collects the error messages in a global array:
$errors_code
I've made a little example of how to use it.
Hello,
jjozsi.
<?php
function submit()
{
/* Lets print the submit button */
print ' <input type="submit" name="Submit" value="Submit"><br />'."\r";
}
function make_tf($var,$label,$required)
{
global $error_code;
/* Lets test, if the user posted the form with the variable name: $var*/
if(!empty($_POST[$var]))
$value=htmlspecialchars(stripslashes($_POST[$var])); /* if yes, lets create a variable to the textfield's value, and don't forget to convert special html characters with htmlspecialchars */
else
{
$value=""; // if the user did not fill that field, lets add an empty as a value
if($required==1)
$error_code[]=$label;
}
if($label!="")
print $label.": "; //if you don't want to add a label to that textfield
/* Lets print a textfield with a variable name $var and a default value with $value */
if(strstr($var,"password"))
{
$type="password";
$value=""; //do not add a default values into password fields...
}
else
$type="text";
if($required==1)
print "(*) ";
print ' <input type = "'.$type.'" name="'.$var.'" value="'.$value.'"><br />'."\r";
}
function errors()
{
global $error_code;
if(isset($error_code))
{
foreach ($error_code AS $rows)
print "<b>$rows</b> must have been filled!<br />\r";
return false;
}
else
return true;
}
?>
<form action="index.php" method="post">
<?php
make_tf("make","Make",1);
make_tf("model","Model",0);
make_tf("username","Username",1);
make_tf("password1","Your first password",1);
make_tf("password2","Your second password",1);
submit();
/* with error() function you can print all the errors connected with this form. It returns false if the user missed some fields, and return true if evrything is OK*/
if(errors()==true)
print "The form could send now, all required fields have been filled";
else
print "Please check the missing fields";
?>
</form>