ivoilic Posted March 3, 2012 Share Posted March 3, 2012 Ok so I wanted to send user input from a form in html send it through Ajax to a Php file, where it would then be messed around with some and output again (The last bit is not important). I have code for sending the info from Ajax to Php. However it is annoyingly long and requires I create a new function for each input. function allrun(){ meaningless = getmeaningless(); if (meaningless != null) { meaningless.open("GET", "Test.php?title=" +document.getElementById('title').value, true); meaningless.send(null); }} How can I collect all the inputs under one function to forward to php? Quote Link to comment https://forums.phpfreaks.com/topic/258153-html-ajax-php/ Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 IMO, you shouldnt have a script(js or php) that automatically collects all fields' input because a simple hacker could just insert their own input fields(like <input type=text name=whatever value='<script>blah blah</script>'>) and potentially mess things up. Personally, I always collect each field individually and set their own individual variables, run them through their proper filters, and then spit the ajax info back. Sorry if that's not what you were asking; if it wasn't please let me know Quote Link to comment https://forums.phpfreaks.com/topic/258153-html-ajax-php/#findComment-1323367 Share on other sites More sharing options...
ivoilic Posted March 3, 2012 Author Share Posted March 3, 2012 So basically do this for each input? Quote Link to comment https://forums.phpfreaks.com/topic/258153-html-ajax-php/#findComment-1323368 Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 I would change the ajax function to ("POST", "process.php") and my process.php page would be the page that processes each input(as a $_POST variable), insert into the database or whatever, and then make the appropriate echo statement(which ajax would spit back out to the page) based on the values that were processed. Personally, I never use GET for forms. Not that POST is really MORE safe, but it helps me visualize things better and the average user can't play around with variables as easily(still can, just not as easily) Quote Link to comment https://forums.phpfreaks.com/topic/258153-html-ajax-php/#findComment-1323371 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.