7

How to post 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 post password and username value to data.php

3 Answers 3

2

You can do it without session or cookie but with pure javascript.Give your iframe an id.

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

You can grab 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 with username and password.

Sign up to request clarification or add additional context in comments.

3 Comments

What is the point of putting the password section in the iframe if you are then getting the value out using JavaScript again?
@SimonH better ask to the person who posted the question. Its answer which address his problem :-)
that is an example . My app is having nearly 50 fields . Its impossible to mention all those . So I explained through an example .
1

try this,

<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 the data.php use the print_r to send back the value to the ajax request

print_r($_POST); 

2 Comments

someone hate you i think
I am having one more query . on change id password i want to display value in main page .
0

If I understood your question correctly, you can store the username and password in PHP session variables and then you can fetch that data from session variables in data.php. As you have two values, its better to store them in an array and then assign the array to the session.

2 Comments

Is there any other solutions except this session ?
I know only cookies other than sessions... Sorry i don't know whether there are any other solutions for it... But as i know we cannot pass the data through URL using POST...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.