Jump to content

Multiple forms on the page and validation


Omzy

Recommended Posts

Basically on my page I have 3 identical forms, for example:

 

 
<form method="post" action="">
<input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : null ?>" />
<input type="text" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : null ?>" />
<input type="hidden" name="form1" />
</form>

 

The hidden variable at the end helps me identify which form was submitted.

 

I've implemented validation and all is fine, apart from one thing. Whenever a form is returned back with validation errors, the matching fields on the other forms also get populated. Obviously this is because they all share the same 'name' attribute, but I have a requirement to keep the same names across all forms.

 

I could of course extend the isset() check to also check for the hidden field, but this creates too much replication.

 

Anybody have an elegant solution to this slight problem?

i'm afraid you're either going to have to name the fields uniquely for the given form, or you'll have to check for the hidden variable as well when repopulating. there's no way for the server to know intuitively which fields to populate.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.