Jump to content

Form Generator


mistergoomba

Recommended Posts

I have a form generator script that I'm using that I think works great. The idea is to call a function (IE: formText) with the parameters for name="", etc. Now, when the form is submitted and there are errors, the script will return the values in $_SESSION['retval'] as an array.

For instance, I can call

[code]formText('username','Choose a Username:');[/code]

This will send $_POST['username'] to the script. If there are errors, it will send $_SESSION['retval']['username'] back to the form. The function will look something like this:

[code]function formText($key,$text){
     echo $text.' <input type="text" name="$key" value="'.$_SESSION['retval']['username'].'">';
}[/code]

The only issue I have with this, is when trying to pass an array. Take, for example this form which the user can add many usernames.

[code]formText('teacher[username]','Choose a name for the teacher:');
formText('student[username]','Choose a name for the student:');[/code]

This code will pass the correct information to the script in the form of $_POST['teacher']['username'], however when being returned to the form, the variable will look like this: $_SESSION['teacher[username]']. I've created a few extra lines of code that will detect the error and fix it, however I would like to know if anyone in the forum has a better suggestion. Maybe there is a better way to go about this whole thing.

Thanks in advance for your help!
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.