469,325 Members | 1,516 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

Submit PHP $_POST with AJAX

91
I have a form in PHP that needs to be processed by the same page. I have ajax calling the page and parsing the data however I cannot get the POST data to be sent via AJAX to the PHP Page. I found this site which gives me an idea that you need to setup the $_POST methods as what looks like a GET then you send the information to the PHP page which in turn interprets it as $_POST data.

However I was wondering is there a way that without me having to put in ALL the names of the forms elements that it can loop through and add the name plus the value itself?

Expand|Select|Wrap|Line Numbers
  1. <form method="post" accept="text/plain" action="javascript:LoadData('/admin/edituser/<?=$_REQUEST[2]?>/save');">
  2. <fieldset>
  3. <legend>User Details:</legend>
  4. <table class="EditForm">
  5. <tbody>
  6. <tr><td>Name:</td>
  7. <td><input type="text" name="name" maxlength="155" value="<?=$results['Full_Name']?>"></td></tr>
  8. <tr><td>Title:</td>
  9. <td><input type="text" name="title" maxlength="155" value="<?=$results['Title']?>"></td></tr>
  10. <tr><td>Email:</td>
  11. <td><input type="text" name="email" maxlength="155" value="<?=$results['Email'] ?>"></td></tr>
  12. <tr><td>AD Account:</td>
  13. <td><input type="text" maxlength="25" name="ad" <?=$results['AD'] ?>></td></tr>
  14. <tr><td>Receive Alerts:</td>
  15. <td><input type="checkbox" name="alerts" value="1" <?=$func->iif($results['Send_Alerts'],"checked","") ?>></td>
  16. </tr>
  17. </tbody>
  18. </table></fieldset><br>
  19. <fieldset>
  20. <legend>Access Details:</legend>
  21. <table class="EditForm">
  22.  
  23. <tbody>
  24. <tr>
  25. <td><input type="checkbox" name="access[]" value="1" <?=$func->iif($func->inAccess(AL_LOGIN,$results['Access']),"checked","") ?>>Login</td>
  26. <td><input type="checkbox" value="2" name="access[]" <?=$func->iif($func->inAccess(AL_GRAPHS,$results['Access']),"checked","") ?>>View Graphs</td>
  27. <td><input type="checkbox" value="4" name="access[]" <?=$func->iif($func->inAccess(AL_TSM_LIST,$results['Access']),"checked","") ?>>View Other TSMs<br>
  28.     </td></tr><tr><td><input type="checkbox" name="access[]" value="256" <?=$func->iif($func->inAccess(AL_ADD_USER,$results['Access']),"checked","") ?>>Add User<br>
  29.     </td><td><input type="checkbox" value="512" name="access[]" <?=$func->iif($func->inAccess(AL_EDIT_USER,$results['Access']),"checked","") ?>>Edit User<br>
  30.     </td><td><input type="checkbox" value="1024" name="access[]" <?=$func->iif($func->inAccess(AL_REMOVE_USER,$results['Access']),"checked","") ?>>Remove User<br>
  31.     </td></tr><tr><td><input type="checkbox" value="2048" name="access[]" <?=$func->iif($func->inAccess(AL_EDIT_CONFIG,$results['Access']),"checked","") ?>>Edit Config<br>
  32.     </td><td><input type="checkbox" name="access[]" value="4096" <?=$func->iif($func->inAccess(AL_CHANGE_TEMPLATE,$results['Access']),"checked","") ?>>Change Template<br>
  33.     </td><td>
  34.     </td></tr><tr><td colspan="3">Access Level (higher can edit lowers access)<br>
  35.     <input type="radio" class="a_level" name="a_level" value="0" checked>None <input type="radio" class="a_level" name="a_level" value="16384" <?=$func->iif($func->inAccess(AL_LEVEL_1,$results['Access']),"checked","") ?>>1 <input type="radio" class="a_level" name="a_level" value="32768" <?=$func->iif($func->inAccess(AL_LEVEL_2,$results['Access']),"checked","") ?>>2 <input type="radio" class="a_level" name="a_level" value="65536" <?=$func->iif($func->inAccess(AL_LEVEL_3,$results['Access']),"checked","") ?>>3 <input type="radio" class="a_level" name="a_level" value="131072" <?=$func->iif($func->inAccess(AL_LEVEL_4,$results['Access']),"checked","") ?>>4 <input type="radio" class="a_level" name="a_level" value="262144" <?=$func->iif($func->inAccess(AL_LEVEL_5,$results['Access']),"checked","") ?>>5 <input type="radio" class="a_level" name="a_level" value="524288" <?=$func->iif($func->inAccess(AL_SYSTEM_ADMIN,$results['Access']),"checked","") ?>>System Admin</td></tr>
  36.     </tbody>
  37.     </table></fieldset>
  38. <br>
  39. <fieldset>
  40. <legend>TSM Report Properties:</legend>
  41. <table>
  42.  
  43.     <tbody>
  44.         <tr>
  45.             <td>Name:</td>
  46.             <td><input type="text" name="tsm_name" value="<?=$results['Name'] ?>"></td>
  47.         </tr>
  48.         <tr>
  49.             <td>Group:</td>
  50.             <td><select name="tsm_Group">
  51.             <? foreach($enums as $key)
  52.                 {
  53.                     echo "<option ".$func->iif($key==$results['Group'],'selected','').">".$key."</option>";
  54.                 } ?>
  55.             </select></td>
  56.         </tr>
  57.         <tr>
  58.             <td>Include in reports:</td>
  59.             <td><input type="checkbox" name="tsm_include" value="1" <?=$func->iif($results['Include'],"checked","") ?>></td>
  60.         </tr>
  61.     </tbody>
  62. </table></fieldset>
  63. <br>
  64. <table><tr><td><input type="submit" value="Save" name="UserEdit_Save"></td><td><a
  65.     href="javascript:LoadData('/users');">Cancel</a></td></tr></table></form>
  66.  
Mar 26 '08 #1
3 3314
acoder
16,027 Expert Mod 8TB
You will have to add the elements/values manually. You can loop over all the form elements and check their types and deal with each one accordingly, e.g. checkbox/radio buttons and select elements are dealt with differently from text boxes.
Mar 26 '08 #2
arggg
91
You will have to add the elements/values manually. You can loop over all the form elements and check their types and deal with each one accordingly, e.g. checkbox/radio buttons and select elements are dealt with differently from text boxes.
Could you give an example please?
Mar 26 '08 #3
acoder
16,027 Expert Mod 8TB
See this link (serializeForm).
Mar 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by lsarg | last post: by
3 posts views Thread by Taras_96 | last post: by
1 post views Thread by kkuniya | last post: by
1 post views Thread by gzannd | last post: by
12 posts views Thread by Daniel Klein | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.