Note that there are some explanatory texts on larger screens.

plurals
  1. POajax form not updating values
    primarykey
    data
    text
    <p>I've got this form that updates user information on db. However, this functionality is not working with ajax (works with a simple submit with refresh).</p> <p>This postes form serialized data to the server <strong>jQuery</strong></p> <pre><code> $('#commit-changes').click(function(){ $('#validation').submit(function(){ $.ajax({ type: "POST", data: $("#validation").serialize(), cache: false, url:"modules/user/updateuser.php", success : function(data){ $("#response-update").html(data); }, error:function(){ alert("ERROR"); } }); }); }); </code></pre> <p>Here's the HTML that outputs the markup <strong>HTML</strong> </p> <pre><code> $rcs_roles = $user-&gt;getRoles(); $role =''; foreach($rcs_roles as $roles) { if($roles-&gt;role_number == $rcs_user-&gt;permissao) $role .= '&lt;option value="'.$roles-&gt;role_number.'" selected="selected"&gt;'.$roles-&gt;role.'&lt;/option&gt;'; else $role.= '&lt;option value="'.$roles-&gt;role_number.'"&gt;'.$roles-&gt;role.'&lt;/option&gt;'; } if($rcs_user-&gt;activo == 0) { $activo = '&lt;input type="checkbox" name="activo" class="on_off_checkbox" value="1" /&gt;'; } else { $activo = '&lt;input type="checkbox" name="activo" class="on_off_checkbox" checked="checked" value="1" /&gt;'; } $response = ''; $response.='&lt;form id="validation" action="" method="post"&gt; &lt;fieldset &gt; &lt;input type="hidden" name="user_id" value="'.$_POST['user_id'].'"/&gt; &lt;legend&gt;Actualizar Dados Utilizador&lt;/legend&gt; &lt;div class="section "&gt; &lt;label&gt;Nome&lt;small&gt;Insira o seu nome&lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;input type="text" class="validate[required,custom[onlyLetterSp]] large" name="nome" id="f_required" value="'.utf8_encode($rcs_user-&gt;nome).'"&gt; &lt;/div&gt; &lt;/div&gt;'; $response.='&lt;div class="section "&gt; &lt;label&gt; Email&lt;small&gt;Insira o seu email&lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;input type="text" class="validate[required,custom[email]] large" name="email" id="e_required" value="'. utf8_encode($rcs_user-&gt;email).'"&gt; &lt;/div&gt; &lt;/div&gt;'; $response.= '&lt;div class="section"&gt; &lt;label&gt;Permissões&lt;small&gt;Seleccione o tipo de utilizador &lt;/small&gt;&lt;/label&gt; &lt;div&gt; &lt;select class="medium" name="role"&gt; '.$role.' &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="section"&gt; &lt;label&gt;Activo&lt;small&gt;Activar utilizador&lt;/small&gt;&lt;/label&gt; &lt;div&gt; '.$activo.' &lt;span class="f_help"&gt;ON / OFF &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="section last"&gt; &lt;div&gt; &lt;a id="commit-changes" class="uibutton submit_form" name="submit" &gt;Gravar&lt;/a&gt;&lt;a class="uibutton special" onClick="ResetForm()" title="Limpar Formulário" &gt;Limpar Formulário&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt;&lt;/form&gt;'; </code></pre> <p>And then the server side processing <strong>PHP</strong></p> <pre><code>$response=''; $id_user = $_POST['user_id']; $name = utf8_encode($_POST['nome']); $email = utf8_encode($_POST['email']); $permitions = $_POST['role']; if(!isset($_POST['activo'])) { $active = 0; } else { $active = 1; } $user = new Users(); try { $user-&gt;updateUsers($name, $email, $permitions, $active, $id_user); $response = "SUCESSO"; } catch (Exception $e) { $response = "ERRO".$e-&gt;getMessage(); } echo $response; </code></pre> <p>Glad for all the help I can get</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload