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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.