Forum Moderators: coopster
It was not a problem until I needed to deal with a few too many fields!
Will writing to a temp table and feeding
<? echo $biz_name;?> with the temp value do?
While I type I imagine that for each fields where I use!preg_match() a preg_match() could match the input and save it
However the concept although doable sounds heavy
any other suggestion
Not sure that I would like adding a JS piece
Any other ideas
PS)
I do not like too much the idea of passing through session a user's details but I keep out of it the UN and PW
if a session is stolen only non financial and non personal details could be revealed
print "
<form....>
<input type='text' size=40 name='name' value='$_POST[name]'>
......
</form>
";
That way the next time the form is shown it will show the previous values that they entered in. Then they also have the option of changing those values, but at least it will be there for them if they don't.
Hope this helps
eelix
i know how you feel because it's quite a lot work to produce a useable web-form with error checking.
in a general approach you have the different input fields and their default values. these defaults are assigned to php variables - each field often has an according variable.
with these two things already done, the next step is to integrate these default values into the xhtml form. htmlspecialchars() does a great job here to put things like quotes as default (or later on submitted) values into the input elements:
<form method="post" action="">
<input name="field1" id="field1" value="<?=htmlspecialchars($form_field1)?>" size="32" />
</form>
as an example.
please check, if you're fine with this so far. modify $form_field1's value a bit and see if your page reflects the changes, because when you don't see $_POST values, you might not see even normal values.
Hi Hackre,
Nothing short of writing to a db or creating a session seems to work
But even the DB solution is moot for I cannot refer to any field or ID that does not yet exist so I cannot do a WHERE etc...
I might have pushed a tad too far security check
But I am pretty happy with the results, it checks for omissions and give precise feedbacks
Same with miss typing or using wrong characters
Funny when you try to be highly safe and very thorough simple stuffs become to need lot of room!
My 10 fields form calls a script 600 lines long :)
And I cannot find a “light” way to pass back value to the form ..........
i've just today been working on that very thing, lol
i process the form on the same script as i display it.
i have found the key is to use a separate template for the html form (see bottom of post) and ob_start() to insert the POST'ed values into before you display the errors.
so when you call your error checking routine, you can pass this filled-in template, to the display error function
if (!$submit)
{
// display form
// the entire form is in an html template as suggested above
ob_start(); include($_SERVER['DOCUMENT_ROOT'] . '/templates/forms/contact_us.htm');
$page_content = ob_get_contents(); ob_end_clean();
echo $page_content;
// see the quote at the bottom of this message for the html form template
}
else
{
// do error checking
if ($e->num_errors() > 0)
{
// if there are errors, include the same form template, now with the POST values filled in, and then pass that variable to the display error function.
ob_start(); include($_SERVER['DOCUMENT_ROOT'] . '/templates/forms/contact_us.htm');
$page_content = ob_get_contents(); ob_end_clean();
$e->display_errors($page_content);
}
}
HTML form template:
<form method="post">
Name <input type="text" size="30" name="name" value="<?php if (isset($_POST['name'])){echo $_POST['name'];}?>">
Email <input type="text" size="30" name="email" value="<?php if (isset($_POST['email'])){echo $_POST['email'];}?>">
<input name="submit" type="submit" value="Send">
</form>
clear as mud?
I am thinking that with such a system
we can explode the error field
use preg and on the fly highlight where the error is in the field that contains the error
i'll have to play with that.
great idea!
added:
henry, i've just been thinking about how to do that, would you mind going into detail - would you read the entire template into an array (using file()) and then try preg_match on each line?
cheers