Welcome to WebmasterWorld Guest from 54.162.151.77

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Stop form field clearing after error?

     
8:18 pm on Oct 16, 2011 (gmt 0)

New User

5+ Year Member

joined:Oct 3, 2011
posts: 7
votes: 0


Hi everybody,

I have a really annoying problem on my site. I currently have a field for an "Add Listing" page and it automatically generates a "Ref ID" from the database and shows it as a frozen field. It's written like this...

$form->field('frozen', $lng['user']['RefID'], 'RefID', $formSubmit['RefID'], '', '', false, '25', '255');


The problem is, if the user creates an error and has to redo the form, the field clears automatically because the field is frozen, the listing is submitted without a Ref ID.

Is there anyway I can stop this field from clearing? Or better still, just presenting the Ref ID as text above the form?

Thanks everyone,

Simon :)
8:13 am on Oct 17, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2007
posts:221
votes: 0


Do you reshow the form automatically if there is an error, or does the user have to go back to the form?
11:11 am on Oct 17, 2011 (gmt 0)

New User

5+ Year Member

joined:Oct 3, 2011
posts: 7
votes: 0


Hi Status_203,

I reshow the form automatically with an error message at the top of the page.

Thanks for your help,

Simon
7:52 am on Oct 18, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2007
posts:221
votes: 0


Then you need to get the submitted value of the field from $_GET or $_POST depending on the form method and use it populate the default value of the form control.

Something along the lines of: (untested)

$defaultValue = '';
if (array_key_exists('field_name', $_GET)) {
$defaultValue = $_GET['field_name'];
}
echo '<input type="text" name="field_name" value="' . htmlspecialchars($defaultValue) . '">";
1:00 pm on Oct 18, 2011 (gmt 0)

New User

5+ Year Member

joined:Oct 3, 2011
posts: 7
votes: 0


Hi Status,

Thanks for your reply! So I'd just put this code within the code I have included further up?

I'm a bit of a novice with this!
8:40 am on Oct 19, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2007
posts:221
votes: 0



$form->field('frozen', $lng['user']['RefID'], 'RefID', $formSubmit['RefID'], '', '', false, '25', '255');


You appear to be using some form of form generating class. Do you happen to know which one? If not, what files are included/required at the top of the file that includes this line?

If you feel like experimenting it could be that one of the '' parameters is used as the default value - try using the equivalent of $defaultValue from my example in place of one of the empty set of quotes. If it doesn't work replace the empty quotes and try it in place of the other set of quotes.