Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/258153-html-ajax-php/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/258153-html-ajax-php/#findComment-1323367
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/258153-html-ajax-php/#findComment-1323371
Share on other sites

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.