Jump to content
bubbles

Problema validare javascript + php

Recommended Posts

Posted

Am urmatorul cod :


<script type="text/javascript">
function v_title()
{
var tgt=document.getElementById("title");
if (tgt.value=='') { return 0; }
else { return 1;}
}

function v_keywords()
{
var tgt=document.getElementById("keywords");
if (tgt.value=='') { return 0; }
else { return 1; }
}



function v_submit()
{
var ok=0;
ok+=v_title();
ok+=v_keywords();
if(ok==2) document.f_formular.submit();
else alert("Formularul nu este completat corect.");

}

</script>
<?php

if ( isset( $_POST['xxxx'] ) ) { echo "test test test "; }

?>

<form method="post" name="f_formular" action="">
<input type="text" name="title" id="title" /><br/>
<input type="text" name="keywords" id="keywords" /><br/>
<input type="button" onclick="v_submit();" name="xxxx" value="Add"/>
</form>

Nu inteleg si nici nu reusesc sa fac sa afiseze test test test cand apas pe butonul xxxx dupa ce trece si de validarea facuta in javascript.

if ( isset( $_POST['xxxx'] ) ) { echo "test test test "; }

Care este problema ?

Posted
pune if ( isset( $_POST['title'] ) ) { echo "test test test "; }

pentru ca $_POST['xxxx'] nu exista ... verifica cu print_r($_POST) ;)

Nu exista pentru ca a pus <input type="button" . Nu exista type="button" , exista doar type="submit".

Posted
Nu exista pentru ca a pus <input type="button" . Nu exista type="button" , exista doar type="submit".

Exista:

type=button este pentru un simplu buton.

type=submit este pentru submitul forumului.

Posted (edited)

JavaScript can be used to validate data in HTML forms before sending off the content to a server. I am having some trouble with this script for form validation, using initially java script and then validating again and the submitting with php.

Edited by evangilbort

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.   Paste as plain text instead

  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...