简体   繁体   中英

php Form in steps (autosave after step 2)

I'm doing a project and i'm stuck, Hoping someone can help me with this part of my project please :)

In trying to create a simple classifieds section on my website, I had a form for various information which worked fine, then trying to add images to the database i fell into a problem as the listing wasn't created so the images wouldn't tie in. So i decided to do a form with 4 steps... Step 1, choose category, step 2, fill in description, step 3, add photo's, step 4, View listing and confirm it.

Please could someone help me as i'm stuck. What i would like is... Step one. Choose category Step two. Fill in title and description ( Then on clicking to step three it will save the data from steps one and two to mysql database. This is where i'm stuck ) Step three. Add pictures Step four. Review listing and confirm it. (Will activate in db)

The steps i downloaded from code canyon as i thought this would be an easier and user friendly way.. :) I look forward to your replies and hope i've given enough information:)

Thank you!

You can do either using AJAX or php sessions.

Here is the AJAX way

function autosave() {

new Ajax.Request('autosave.php', 
{ 
    method: 'post',
    parameters: {id: $('id').value, save_text: $('myInput').value},
});

}

Now call this function with some Interval.

Other way is you need to place you code in php session and you need to habdle it like - every action you need to save your session data, sameway you need to load if you do back and forward.

Provide more details about php version, some forms, fields and database, I will edit my answer

Since you're new to PHP I'll give you an idea of what to look for. If your page doesn't use AJAX then validate the post data at each submission. If the post data is valid then save it into the session (use the $_SESSION superglobal) and save it to the database at whichever step you need and wipe out the data you just placed in the session.

Alternatively you can use AJAX and just submit the form when the required steps are completed.

Since you didn't provide any code I won't either, but I figure a nudge in the right direction wouldn't hurt. Come back and post another question when you have some code if you get stuck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM