Topic: save form values into a database/array if user clicks an a href link

Hi at all.

first - thanks for the great job of xajax. it's a bomb for me smile

i've read and searched the forum. and take a look at the documentation. but i'm a little bit new at xajax and ajax/javascript.

i've got a question. i have a form with several input fields. also a submit button, so send all my values via $_POST and then i write this values into a database.
all things work very well. also i have several links on this site. this links jump to another page or load some other functions do to something. (use $_GET).

now - i enter something into my fields in my form and i forget so save the entry via my submit button. all inputs are lost.

i don't know the exactly syntax in xajax to save all my inputs from my fields if i click an a href link. my idea is somethink like this:

<a href=next_side.php onClick="xajax_saveAllMyInputs(  ??WHAT HERE??     );">Other Side</a>

the function should do something like this:

function saveAllMyInputs($_POST) {

    /* manage the $_POST or inputs from my form or inputfileds like comment, name, shurename, after .... */

    $db->connectToDB();

    /* do something - write into database and save all inputs (insert or update if ID allready exists */


   jump to the new side

}


any ideas to begin or some hints ?

many thanks

Andy

Re: save form values into a database/array if user clicks an a href link

here is my try. the button works. but if i use the link, noting works:

<?PHP

require("../xajax/xajax_core/xajax.inc.php");

$xajax = new xajax();

$xajax->setFlag('debug',true);
$xajax->configure('javascript URI','../xajax');

$xajax->register(XAJAX_FUNCTION,'saveMyData');

function saveMyData($data) {
   $foo = $data['what'];
   $id  = $data['id'];

   $response = new xajaxResponse();
   $response->assign('whatId', 'value', $foo);
   $response->assign('whatId', 'innerHTML', $foo);
   $response->append('whatId', 'innerHTML', " - " . $id);

   return $response;
  }

$xajax->processRequest();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Test</title>
<?php $xajax->printJavascript(); ?>

<script type="text/javascript">
  function doSomething() {
    xajax_saveMyData(xajax.getFormValues("myForm"));
    return false;
   }
</script>

</head>
<body>
<a href=?id=3 onClick="doSomething();">click</a>
<br><br><br>
<form method="POST" id="myForm">
Eingabe: <input type="text" name="what">
<br><br>
<input type="button" value="click" onClick="xajax_saveMyData(xajax.getFormValues('myForm'));">
<input type="hidden" value="<?php echo $_GET['id']; ?>" name="id">
</form>
<br />
<div id="whatId"> ..... </div>
</body>
</html>



EDIT: the link can be ?id=3&cat=34&res=true or something else ...

Re: save form values into a database/array if user clicks an a href link

How about:

1. The link onclick calls your registered function passing both the form values and the href from the link.
  <a href="#" onclick="xajax_saveMyData(xajax.getFormValues('myForm'), 'nextpage.php'"); return false">Go</a>

2. Your function updates the database using the form values.

3. Your function uses the response->redirect() function to get to the new page.
   $response->redirect($nextpage');


Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: save form values into a database/array if user clicks an a href link

edrobinson wrote:

How about:

1. The link onclick calls your registered function passing both the form values and the href from the link.
  <a href="#" onclick="xajax_saveMyData(xajax.getFormValues('myForm'), 'nextpage.php'"); return false">Go</a>

2. Your function updates the database using the form values.

3. Your function uses the response->redirect() function to get to the new page.
   $response->redirect($nextpage');


Ed

to 1: ah, ok. i understand !

2-3: ok - i'll try it.

is there any chance to transmit or get the url string into an variable ?
like a link like this: <a href="test.php?id=12&edit=true" onclick="xajax_saveMyData(xajax.getFormValues('myForm'), 'nextpage.php?id=13&edit=true'"); return false;">Go</a>

now, when my url is this: http://localhost/test.php, i have no id.
when i click my link, <a href="test.php?id=12&edit=true" onclick="xajax_saveMyData(xajax.getFormValues('myForm'), 'nextpage.php?id=13&edit=true'"); return false;">Go</a>
xajax doesn't transmit this ... the url isn't changing. that's ajax. thats ok ... but how can i figure out my $_GET parameters in my registered function?

i haven't found something in the forum and in the documentation.

thanks for any tipps.

Andy

Re: save form values into a database/array if user clicks an a href link

Andy,

You could put the id in a hidden variable on the page or you could use sessopn variables. Then you could construct the query string in your function and use it in the redirect call.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: save form values into a database/array if user clicks an a href link

Considering to buy an app in AppStore? Visit AppDB first and try that app for free!         
No limited or trial versions, only fully working games and applications.         
         
Over 30 000 apps and growing! These are some of them:         
Audaria
Barbershop
2ch Blog Reader
Dead Man's Dice
Love Compatibility
         
And remember to support software developers. If you like their products, buy it!