Data Needs To Be Stored In Html Elements Automatically Before Server Validation Occurs
Solution 1:
@Jim, this is the same situation as in your original question.
(Before anybody points out that it is a different account, it's the same actual person - long story!)
PHP will not keep the "state" of the control when you send it back to the browser after a post-back.
So instead of sending back the following each and every time...
<input type="text" id="mytext" name="mytext">
You need to send back what was originally entered as part of the control...
<input type="text" id="mytext" name="mytext"
value="<?php echo $_POST['mytext']; ?>>
With checkboxes and radios (which was your original question), you need something like...
<input type="checkbox" id="mycheck" name="mycheck"
value="<?php echo (isset($_POST['mycheck']) ? "checked" : ""); ?>>
And as you're talking about <textarea>
controls, you'd do something like...
<textarea id="mytext" name="mytext"><?php echo $_POST['mytext']; ?></textarea>
Update
As you are building the HTML into the $echo
string variable (rather than just having the HTML mark up directly), you need to include the above code as part of the string.
If you do an echo
command during the building of the string, the thing being echo
ed will be sent to the screen straight away. Then when you send the contents of $echo
via the command echo $echo;
you get everything else.
So, for a single line textbox you would do...
$echo = '<input type="text" id="mytext" name="mytext" value="'. $_POST['mytext'] .'">';
For a checkbox you would do...
$echo = '<input type="checkbox" id="mycheck" name="mycheck" '. (isset($_POST['mycheck']) ? "checked" : "") .'>';
For a multi line textbox you would do....
$echo = '<textarea id="mytext" name="mytext">'. $_POST['mytext'] . '</textarea>';
So you see that we are including the existing value of the control as part of the string that you are building.
Solution 2:
it needs to be
<div id="ArticlesOrderForm" class="formGroup">
<legend>Articles Order Form</legend>
<b><label for="article_keywords">Keywords/Titles<span class="reqd">*</span> : </label></b>
<textarea rows="6" cols="50" id="article_keywords" name="article_keywords" ><?php echo $_POST["article_keywords"]; ?></textarea>
<b><label for="article_keywordDensity">Keyword Density (Optional): </label></b>
<textarea rows="6" cols="50" id="article_keywordDensity" name="article_keywordDensity" ></textarea>
But why not use JavaScript validation?
This jQuery Plugin is pretty awesome and easy to use:
http://docs.jquery.com/Plugins/Validation
You add the validation type by simply adding classes like required or email.
Post a Comment for "Data Needs To Be Stored In Html Elements Automatically Before Server Validation Occurs"