How to post field value which is available in iframe in php

How to send iframe value in php.

Example: Username.php

<form action='data.php' method='post'> <input type='text' name='username' id='username'> <iframe src='password.php'></iframe> <input type='submit'> </form> 

Password.php

 <input type='text' name='password' id='passwprd'> 

I want to send the password and username in data.php

+6
source share
3 answers

try it,

 <form action='data.php' method='post'> <input type='text' name='username' id='username'> <iframe id="iframe_pass" src='password.php'> </iframe> <input id="submit" type='button' value="submit"> </form> <p id="password_from_frame"></p> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $("#submit").on('click', function(){ var pass_field = $("#iframe_pass").contents().find("#password"); var username = $("#username"); var data = {username : username.val(), password : pass_field.val()}; // make an ajax call to submit form $.ajax({ url : "data.php", type : "POST", data : data, success : function(data) { console.log(data); alert(data); }, error : function() { } }); }); // you can use keyup, keydown, focusout, keypress event $("#iframe_pass").contents().find("#password").on('keyup', function(){ $("#password_from_frame").html($(this).val()); }); </script> 

and password.php

 <input type='text' name='password' id='password'> 

and on data.php use print_r to send the value to the ajax request

 print_r($_POST); 
+1
source

You can do this without a session or cookie, but with pure javascript. Make your iframe id.

 <iframe id='iframePassword' src='password.php'></iframe> 

You can capture username with this

  var username = document.getElementById('username').value; 

You can access the password field inside the iframe with this.

 var ifr = document.getElementById('iframePassword'); var password = ifr.contentWindow.document.getElementById('passwprd').value; 

Now make an ajax call using username and password .

+2
source

If I understand your question correctly, you can save the username and password in the PHP session variables, and then you can extract this data from the session variables in data.php. Since you have two values, it is best to store them in an array and then assign the array to a session.

0
source

Source: https://habr.com/ru/post/983100/


All Articles