Jump to content

I'm going round in circles with forms and SQL?


MrScabby

Recommended Posts

Hi again all,

 

I think I'm going round in circles here trying to chose a method to populate a form with a chosen name. I also think with a well crafted reply could put me right and save more lost hours.

 

Im new to this area of coding and you could say not practised. So with a few months till my next module I thought I would reaffirm my current knowledge by launching into a project. Lol, even the smallest of ideas can involve hours and hours of commitment.  I think though in my current problem Im lost because there are so many answers and I cannot decide what or which to chose.

 

The specification is creating the registration part of a website, New User, Edit User, Delete User - sounds simple but Im trying to make it work similar to a web app so I would expect a lot of interaction between the server and the client - There is a comboBox at the top populated with the 'profile_name' information.

I want the user to select a name and the form underneath the combobox to fill with all the other information. as this is only a simple practice I only need a simple form with 5 or so fields per row profile_name,profile_alias,profile_email,profile_phone,profile_mobile in a table called 'profiles'.

 

So Im thinking I will need an 'onchanged' event so when a new name is selected I can call a javascript function to go get the info for the rest of the form, this will be returned by the php script and I then populate the form. And this is where I get stuck - As I re-write the keywords to dig out more articles about moving variables between server and client and vice-versa, the more work I dig up for myself. I mean what is the best/easiest to do?

 

I would have thought something like this would have a simple method or function alas no. Ajax, Json, Cookies, Headers, XML, ??? and so on. I ended up confused and looking at months of learning just to send/receive variables. I think asking is the best thing here,

 

On a different note, do I really have to rewrite the entire form everytime someone selects a different name from the combobox? It would be best if the form remained static and the content of the html boxes changed. Is this possible? and do I have my understanding of the relationship between client and php server wrong here? I was thinking the server had some control over data but if I echo the php results as said in some of the articles then my form is refreshed with a blank screen. I suppose I could change the php to rebuild the form but am I again choosing the hardest method?

 

Thanks in advance, Phil

Edited by MrScabby
  • Like 1
Link to comment
Share on other sites

First, New/Edit/Delete user are three different things. Was your description only talking about the Edit portion?

 

Second, I'm not sure about this combobox (I assume you mean a textbox with autocomplete?) being the best way to find a user. If I needed to edit a user, would I want to use a search page first? Often the process is to search for the user to edit, check the search results to see I got the right person, then click a link/button to go to the edit page.

 

Third, AJAX. That's the thing.

- AJAX is what lets your Javascript communicate with PHP

- JSON is a way of sending data back and forth between the two

- Cookies are the things that keep you logged in on websites (among other things they do) but you don't really need to worry about that for this

- Headers, again don't need to worry much about those

- XML is another way of sending data, but JSON won that battle as far as AJAX is concerned

 

Fourth, rewriting the form. There are a million ways you could do this. What I'm thinking right now is:

1. In your Javascript you keep track of the various form elements and what piece of data they represent (eg, username or email)

2. The AJAX returns a simple blob of data in JSON. Maybe it looks like

{
	"name": "MrScabby",
	"email": "myscabby@example.com",
	"phone": "123-555-7890"
}
3. Use Javascript to update every form element according to the data returned. For example, a textbox corresponding to the name will get the name value. Do this very generically, even if it's just a lot of if the element is a textbox then { ... } else if it is a list then { ... } etc, then apply that to everything you can. Edited by requinix
Link to comment
Share on other sites

Thanks for that,

Yes requinex, AJAX does sound the ticket. I was going in circles trying to work out which method to use. When you start looking you get the feeling people have their own methods they prefer, I have read tricks using all sorts of coding techniques and in the end all it served was to confuse me...

I'm reading right now, lets hope there isn't too much of a learning curve...

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.