Jump to content

Archived

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

mistergoomba

Form Generator

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!

Share this post


Link to post
Share on other sites

×

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.