php - Automatically filling a form and submitting it doesn't get the parameters to the server -


i have form filled automatically js

my form is:

<form id="dosubmit" method="post">     <input type="text" id="usr" />     <input type="password" id="pwd" /> </form> 

my js is:

document.forms["dosubmit"].elements["usr"].value = usr; document.forms["dosubmit"].elements["pwd"].value = psw; document.forms["dosubmit"].action = location.pathname + "user"; document.forms["dosubmit"].submit(); 

now on next page php, when try use error undefined index , when type print_r($_post) array()

any idea how can post form data on next page?

your input elements need have name attribute:

<form id="dosubmit" method="post" action="">     <input type="text" id="usr" name="usr" />     <input type="password" id="pwd" name="pwd" /> </form> 

after you've done this, should able see usr , pwd keys in $_post array in receiving php script. (the keys html name attribute , value corresponding value html attribute.)

so, form ended looking this:

<form id="dosubmit" method="post" action="">     <input type="text" id="usr" name="usr" value="someuser"/>     <input type="password" id="pwd" name="pwd" value="somepassword"/> </form> 

your $_post array this:

array (   'usr' => 'someuser',   'pwd' => 'somepassword' ) 

jsfiddle example


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -