Jump to content

Recommended Posts

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.  ???

Link to comment
https://forums.phpfreaks.com/topic/132612-php-and-javascript-working-together/
Share on other sites

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.

 

 

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?

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 = '..'

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.