I have two files one is index.php which contains a form which gets submitted to abc.php.Now the problem is have a frame in index.php where in i want to display the datas that i got after submitting the form to abc.php.I tried but m not able to it.Hope i hav mentioned all the thngs required. Any suggestion will be appreciated.
Set your form's target (phpfiddle demo):
<?php
if(!empty($_POST['submit_to_frame']))
{
echo htmlspecialchars($_POST['the_data']);
}
else
{
?>
<iframe id="the_frame" name="the_frame"></iframe>
<form method="POST" target="the_frame">
<input type="hidden" name="submit_to_frame" value="true" />
<input type="text" name="the_data"/>
<input type="submit" value="OK">
</form>
<?php
}
?>
Related
I have a problem of getting the value of an input element. Thanks in advance for help! This is the sample code:
<form action="#" method="POST">
<input name="X" value="3" />
<?php
//question: how can I put the value of input in a variable
//$_POST['X']; isn't applicable since I am in the same form.
?>
</form>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<input name="X" value="3" />
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['X']) == true){
echo $_POST['X'];
}
?>
First of all submitting a form on its own page is a bad practice because whenever you reload the page the form will submit everytime.
Best approach is that you set the action attribute of form to another file or link.
fileOne.php (where your form is located):
<form action="anotherfile.php" method="POST">
<input name="X" value="3" />
<button type="submit" name="submitForm">Submit</button>
</form>
Then in anotherfile.php you will do this:
$check = $_POST["submitForm"];
If(isset($check))
{
$myInputValue = $_POST["X"];
header("Location: fileOne.php/?val".$myInputValue);
}
Then in fileOne.php you can get the variable and its value which is sent via link in the browser like this:
$getInputValue = $_GET["val"];
Now you can echo out the $getInputValue variable wherever you want.
If the the information is not sensitive this is the best approach you got. But if it is, try saving that value in the session and retrieving in the file where you want. I hope it helps. Typed code via app so it might throw an error. But i think this code will work fine. Good luck!
I have a script that users can submit certain data, and after a submit they can "review" the output and go back to previous page or submit to it again and there is my proble, the submitted page: How can I submit it again to write it to a file?
form.html
<form method="post" action="vaihe2.php">
<input name="laskuttaja" type="text" value="Nimi" size="25">
<input name="submit" type="submit" value="Lähetä" />
</form>
vaihe2.php
<?
$laskuttaja = $_POST['laskuttaja'];
$data = '<B>'.$laskuttaja.'</b>';
echo $data;
?>
So how can I post that $data to next page(vaihe3.php) with submit and let the script write it to a file. I know how php write file works but the post to third page is not working.
If you wat to go back, the secret is in the value of the input.
<input name="laskuttaja" type="text" value="<?php echo(isset($_POST['laskuttaja'])?$_POST['laskuttaja']:"Nimi";?>" size="25"/>
To 'save' data to the next page use $_SESSIONs. They're simple to use. Just remember everywhere you use them, you must have session_start(); on LINE 1! Can't stress that enough!
$_SESSION['data']=$data;
on your third page:
echo$_SESSION['data'];
More on sessions here.
In vaihe2.php
<form method="post" action="vaihe3.php">
<?
$laskuttaja = $_POST['laskuttaja'];
$data = '<B>'.$laskuttaja.'</b>';
echo $data;
echo "<input name=\"laskuttaja\" type=\"hidden\" value=\"".$laskuttaja."\" size=\"25\">";
?>
<input name="submit" type="submit" value="anything" />
</form>
Here you are passing laskuttaja as hidden field and on post will be available to you in third page.
Now data flow as per your requirement. User fills data in form.html -> reviews on vaihe2 and confirms -> gets written in vaihe3.
Could you post the form conditionally back to itself until validated by checkbox? the action would change to "vaihe3.php" ?
<form method="post" action="<?php if ($_POST["valid"]==1) {echo 'vaihe3.php';} ?>">
<input name="laskuttaja" type="text" value="<?php if ($_POST['laskuttaja']!=='') {echo '$_POST[laskuttaja]'} else {echo 'Nimi';} ?>" size="25">
<?php if (isset ($_POST['laskuttaja') && $_POST['laskuttaja']!=="") {
echo 'Please Confirm your answers: <input name="valid" type="checkbox" value="1" />'; } ?>
<input name="submit" type="submit" value="Lähetä" />
</form>
Otherwise, the mention above about CURL would be another option. Or - since your using PHP anyways, you could write the values of form submission to a session array and make them available to all pages until you empty the array.
My question is how do I call input value of user selected which has show by php code from another php.
Normal simple way we get the input this way
$calendar_id_val = $_GET['calendar_id'];
and now it is not working:
For example Show.php, I have one form which show the values from Database and show the result with php variable with While Loop.
<input name="calendar_id" value="<?php echo $calendar_id;?>">
and when user is submit that form I will carry these user selected value and perform insert.php
While you are doing echo in the input use echo $calendar_id_val
You should use form like,
<form action="insert.php" method="get">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>"/>
<input type="submit" name="submit_id" value="Insert"/>
</form>
Insert.php
echo $calendar_id_val = $_GET['calendar_id'];
Does this answer your question?
<form action="insert.php" method="GET">
<input name="calendar_id" value="<?php echo $calendar_id;?>">
</form>
If you want to redirect the user back to show.php, add this to the end of your insert.php script
header('Location: show.php');
exit();
I suggest $_POST var like this:
<form action="insert.php" method="POST">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>" />
<input type="submit" name="submit" value="Submit" />
</form>
insert.php file:
echo $calendar_id = $_POST['calendar_id'];
I have 2 FORMS on a single page, One below the other.
I would like to have such that second form should be always in disable mode.
and Once the first form submit button is pressed and validated second should get activated to enter the data in it.
Is there anything in PHP which can help me on this
You have 2 ways:
1) send validation of first form using ajax, and, if you receive 'true', enable second form.
2) make a POST from first form, if everything is good, set "validated" to 'true' and reload the same page. In the second form "enabling" must be only if you have $validated = true;
The logic below should help you out as a starting point:
<form method="post">
<input type="text" name="name" />
<input type="submit" name="form1" value="Proceed" />
</form>
<form method="post">
<input type="text" name="email"<?php if(!isset($_POST['form1'])) { echo ' disabled="disabled"'; } ?> />
<input type="submit" name="form2" value="Submit"<?php if(!isset($_POST['form1'])) { echo ' disabled="disabled"'; } ?> />
</form>
Of course, it would be much more reliable to use either AJAX to validate the first form, or to have the forms appear on separate pages.
<?php
if(isset($_POST['next'])) {
if($_POST['name']!="") {
$disabled = "";
$val = $_POST['name'];
} else {
$disabled = " disabled='disabled'";
$val="";
}
} else {
$disabled = " disabled='disabled'";
$val="";
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form id="frm1" name="frm1" method="POST" action="">
<label>Name</label><input type="text" id="name" name="name" value="<?php echo $val;?>"/>
<input type="submit" name="next" id="next_frm" value="Next"/>
</form>
<form name="frm2" id="frm2" method="POST" action="">
<label>Address</label><input type="text" name="address" id="address" value="" <?php echo $disabled;?>/>
<input type="submit" name="save" id="save" value="Save" <?php echo $disabled;?>/>
</form>
</body>
</html>
This is somewhat you were looking for ,I hope
You can do it by setting a class on all inputs within second form and set them as disabled of course someone who knows a bit of javascript will be able to change it.
So you can do it as your visual layer, but then check in PHP as well if second form can be passed in case someone wanted to sneak something in.
More complicated approach would be to show images that look like form fields and only change them to inputs where the first form is submitted. That can be done on client or server side
So in reality you will have 3 forms, but one would be "fake"
Thats simple just use if else condition.
// this if condition checks whether the form 1 is submitted or not. If form1 is submitted than form 2 is displayed else form1 wil only be displayed
if(isset($_POST['submit']))
{
//Display your form 2.
}
else
{
//Display your form1.
}
I have read the answer to this question, to execute PHP scripts with the click of a button. But what if I have a "nested button", like this :
<?php
if(!empty($_POST['act'])) {
echo "Ready to rock!";
$someVar = "Rock n Roll";
if(!empty($_POST['act2'])) {
echo $someVar;
} else {
?>
<form method="POST" action="">
<input type="hidden" name="act2" value="run">
<input type="submit" value="Rock It!">
</form>
<?php
}
} else {
?>
<form method="POST" action="">
<input type="hidden" name="act" value="run">
<input type="submit" value="Show It!">
</form>
<?php } ?>
I heard my problem can be solved with jQuery, but I no idea.
anyone please.
To execute a script on the server you use the action property of your form:
<form method="POST" action="myscript.php">
When clicking a input type="submit" the browser will go to to action of the form surrounding the input type="submit"
Nesting is not a issue, as the browser always will look for the 'surrounding' form.
Problem is in second form, so it will never calls in this code, because it fails in first $_POST variable IF statement, because in second form you do not POST variable "act". so you need to add it
<form method="POST" action="">
<input type="hidden" name="act" value="run">
<input type="hidden" name="act2" value="run">
<input type="submit" value="Rock It!">
</form>
with this form you should see echo $someVar;
p.s. if form action property is emtpy, by default it submits form to the same php script
Just like #DTukans said here, you need the hidden field. If you would post the second form, the value of act will be lost if you are not having a hidden field with the value of act from the first form.
In php you can also check which submit button you submitted by giving the input[type="submit"] a name, such as <input type="submit" name="form2">, then you could check if you submitted that form by:
if (isset($_POST['form2'])) {}, but this is not the case here.
Use the hidden input and you will be good to go.