views:

34

answers:

1

I am working with a CMS like system, which has a special field defined for use in its forms.

This field works similarly to google suggest, executing an sql query behind the scenes and displaying results.

The SQL query I am using selects 3 fields from table1, and concatenates them as a result.

What I need to do, is split this new metafield back into 3 distinct fields, so I can insert them into table2 along with the rest of the form.

How would I go about doing this normally in PHP? Javascript? Inbuilt PHP functionality?

I do wonder how much leeway I have as I am using provided input fields, not standard input fields.

A: 

So your problem is that you want the "autocomplete" field to automatically fill out the form with the values of the fields when selected? If so, you probably either need to change the separator to something that can be easily split using Javascript (such as "|") or modify the SQL query and PHP code to ouput the 3 fields separately as well. This may be harder if you haven't written the autocomplete code yourself

HCL
I don´t want the autocomplete field to automatically fill out the form, i want to use the one autocomplete field in place of having seperate textboxes for firstname and lastname. To do this, I need a way to make the text in the autocomplete field be broken up and inserted into firstname and lastname. The problem isn´t what I use as a delimiter(not yet anyway), its to access that field in the first place.
Jacob
If you manage to post the full field (firstname|lastname) as a single value, you can modify the PHP code that handles the information. Example:<input name="name" value="john|smith">Then you can access the individual values by splitting the field with the PHP code that receives the values:$fields = explode("|",$_POST['name']);$firstname = $fields[0];$lastname = count($fields) > 1 ? $fields[1] : "";Alternatively you could of course split the fields using javascript and save them in separate hidden input fields (<input type="hidden" name="firstname" value="john">)
HCL