eva21 Posted November 13, 2008 Share Posted November 13, 2008 Hi what im trying to do is i have a form with a crap load of stuff, check boxes to be checked, fields where users can enter stuff. Is there anyway, that when the user presses "Save changes" That it will throw everything the user modified, into the database without leaving the page? I thought maybe i could make a button, and when its pressed call a javascript function that would call a php function which updates and saves everything to the databse. Please help! I just need to know the best way to do this. ??? Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/ Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 look into AJAX Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689568 Share on other sites More sharing options...
eva21 Posted November 13, 2008 Author Share Posted November 13, 2008 I have read a bit about Ajax, its a little confusing. Any other way? Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689571 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 You can name a submit button 'save' or whatever and have it post like regular but check for what submit button was pushed. if it was the 'save' button you can have the script save the posted info into the db, assign the info to a session array, and header back to the previous page and fill in the blanks with the session array. Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689578 Share on other sites More sharing options...
eva21 Posted November 13, 2008 Author Share Posted November 13, 2008 Wont that cause a glitch when it changes? Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689585 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 when what changes? Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689594 Share on other sites More sharing options...
eva21 Posted November 13, 2008 Author Share Posted November 13, 2008 OK, so what you want me to do is this (dont worry about spelling just getting rough idea) forma.php has...... (all the stuff the user does) button name="save" ...and other buttons form=post action="formb.php" So when i get into formb.php i check to see if the save button was pressed, which it was, and than i do all my updates, and than do a header and go back to forma.php? Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689596 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 yes, but also put the posted info into a session var in formb before the header, and back on forma.php echo the session vars out as the input values. example: test.php <?php session_start(); echo <<<FORMENT Page 1 Form Stuff <br/> <form action = 'test2.php' method = 'post'> a <input type = 'text' name = 'a' value = '{$_SESSION['t1info']['a']}'><br/> b <input type = 'text' name = 'b' value = '{$_SESSION['t1info']['b']}'><br/> c <input type = 'text' name = 'c' value = '{$_SESSION['t1info']['c']}'><br/> <input type = 'submit' name = 'submit' value = 'save'> <input type = 'submit' name = 'submit' value = 'next page'> </form> FORMENT; ?> test2.php <?php session_start(); if ($_POST['submit'] == 'save') { // save stuff do db here foreach($_POST as $key => $val) { $_SESSION['t1info'][$key] = $val; } header("Location: test.php"); exit(); } echo <<<FORMENT Page 2 Form Stuff <br/> <form action = 'test3.php' method = 'post'> d <input type = 'text' name = 'd' value = '{$_SESSION['t1info']['d']}'><br/> e <input type = 'text' name = 'e' value = '{$_SESSION['t1info']['e']}'><br/> f <input type = 'text' name = 'f' value = '{$_SESSION['t1info']['f']}'><br/> <input type = 'submit' name = 'submit' value = 'save'> <input type = 'submit' name = 'submit' value = 'next page'> </form> FORMENT; ?> Or alternatively... same thing with the save/next page submit buttons and header, but instead of session vars, on the top of each page you could run a query to see if there's info in the db and if there is, put that in the value = '..' Quote Link to comment https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/#findComment-689611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.