I have created 3 php pages. The 1st includes the following form:
<form method="POST" name="go" action="search_form_all.php" >
<input name="value" type="text" id="search_form_1" size="65" placeholder="enter name"/>
<input type="submit" value="" name="submit" />
</form>
The 2nd page called "search_form_all.php" includes the php codes that displays the results of the above form. So if the user type a name in form and press submit, the "search_form_all.php" displays all names from my database according to what the user inserts in the search form.
All I want is to have in my 3rd php page a link, that when the user press it to execute the form in 1st page. For example if I enter a name in search form like "john", then I want to be able to go to my third page and press the link, the form to be executed and to return all names "john" from my database. Is this possible?
Yes, this is possible with session variables. An example:
<?php
session_start();
if(isset($_SESSION['views'])) {
$_SESSION['views']=$_SESSION['views'];
} else {
$_SESSION['views']=1;
}
echo "Views=". $_SESSION['views'];
?>
You can also refer to Document Link
Let me know if you need more help.
Related
I'm trying to display user entered value in form A to be part of the url of page B. For example:
Form A:
<form method="post" action="display_annotation_for_pdbid.php" target="_parent">
<fonttdresult><b>Search Database by PDB ID:</b><br/></fonttdresult>
<input type="text" name="pdbid" id="pdbid" placeholder="Enter a PDB ID" style="width:
106px;">
<input type="submit" name="submit" value="Submit">
</form>
So instead of displaying the new page url as display_annotation_for_pdbid, I want it to display something like 'display_annotation?StructureID:1y26' when the user enters 1y26 in form A. Can someone help me with this?
if you use GET method iin your form to post data , variables will automaticlly be placed in URL
Create another file display_annotation_for_pdbid.php which will contain code to redirect to required url. Try below code
display_annotation_for_pdbid.php
<?php
$pdbid = $_POST['pdbid'];
header("Location : display_annotation.php?StructureID=".$pdbid);
?>
<html>
<script>
function changeText()
{
document.getElementById("input1").value = <?php echo '"'.$_POST['input'].'"'; ?>;
return true;
}
</script>
<form name="mainform" action="" method="post">
<input type="text" name="input" id="input1" />
<input type="submit" onclick = "changeText()" name="Submit" value="Submit!" />
</form>
<html>
i have this code here. can you make it work as intended ?
everytime i click Submit! i want to change the value of the textarea to the last input the user inserted.
PHP code is parsed by a PHP interpreter before any HTML output is sent to the browser.
If your form action is the same page and the same form will be shown before and after submission, then you can let PHP print the value of the input field directly into it.
<input type="text" name="input" id="input1" value="<?php echo htmlspecialchars($_POST['input']);" />
If you're trying to revert the value of this input field whenever a user clicks the submit button, then your code (even if it's prone to code injection) should work but this is useless since the page will be requested again when submit is clicked.
I assume you need to fill in
action=""
By the name of your file, like
action="myFile.php"
Few tips :
NEVER trust the user. The user can manually change the value of the input and send some dangerous values in your $_POST variable. You need to check it using filter_input() by example.
Like #Charles said this is pretty simple problem, use google next time.Here for example
I want to use a search option to find the contents in another page.
My Html page:
<form action="search.php" method="post">
<input name="search" type="text"/>
<input type="image" src="images/search-btn.jpg" alt="search-btn" />
</form>
I have 5 topics in another page, say 'products.html'. Topic headings are Film, Music, etc.
So if a keyword, like the headings or some predefined keywords in each topic, is typed and search button is clicked I want to redirect to the products.php page.
The main thing is that i want to get the focus on that particular topic
Now I'm redirecting simply like this:
<?php
$val=$_POST['search'];
if($val=='Music'||$val=='singer')
{
header('Location:http://localhost/products.html');
}
?>
page1.html
<a name='music'></a><!-- This is anchor -->
<a href='#music'>Go to music on same page</a>
page2.html
<a href='page1.html#music'>Go to music on another page</a>
SERVER SIDE:
<?php
if($val=='Music'||$val=='singer'){
header("Location:http://localhost/products#$val.html");
}
?>
You can style your keywords anchors as you wish:
<a name='music'><b>music<b></a>
<span id='music'>music</span>
Within your form post to a page that can deal with the result, save it and then push the user on.
<form action="process.php" method="post" name="search">
This response page will redirect to something like
header("Location: /products.html#music");
Depending on how the form was completed.
Then on your products page add ids that tie this up, for example:
<h2 id="music">Music</h2>
The user will be redirected and the browser will jump to the corresponding anchor or id.
You can also try this technique by using a hidden field, but for the first page JavaScript will work for this
<input name="target" type="hidden" value=""/>
<input name="search" type="text" onkeyup="your-function-to-set-value-on-hidden-field"/>
Set the value if typed keyword is matched with your list and on the second page receive the hidden field value in PHP variable and do the stuff.
Below is my code for a simple form in the create_session.php page. I am using the forma action method to navigate the user to the "QandATable.php" page when the user submits the form. But what I want is that if the user types in the number 1 in the number of sessions textbox, then navigate to the QandATable.php page wheh the user submits the form, else if it is any other number, then when the user submits the form, I want it to go back to the "create_session.php" (Back to its own page). Imagine it like you click on the submit button and it refreshes the page so it goes back to being a blank form, thats what I want to do if the number of sessions textbox contains a number which is bigger than '1'. How can this be done? I am using php and jquery code as well as basic html.
Thank You
<form action="QandATable.php" method="post" id="sessionForm">
<p><strong>Number of Sessions you Require:</strong> <input type="text" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" maxlength="5" /></p>
<p><input class="questionBtn" type="submit" value="Prepare Questions" name="prequestion" onClick="myClickHandler(); return false;"/></p> <!-- Prepare Questions here-->
</form>
At the very top of the QandATable.php script add:
if ($_POST['sessionNum']!=1) {
header("Location: create_session.php");
exit();
}
But as others have mentioned in the comments, you might as well just make the form submit to the create_session.php page and if it's successful then redirect to the next page.
I'm working on a site that gives the users of the site pre-written letters to send to places. All the user has to do is fill out a form and hit continue, then whatever information the user put into the form (like name for example) gets plugged into a pre-written letter on a printable page. A basic example would be if the form asks for Name then you hit continue, on the printable page, it would say:
Hi, my name is Zach.
I'm using a php based content management system so it should be in php. I know this is a very simple thing to do for those who know how to do it, I unfortunately don't. Thank you in advance for your help!
Suppose you have this form:
<form action="preview.php" method="POST" >
<input type="text" name="name" />
<input type="submit" value"Print" />
</form>
When you hit submit, the values of all the fields (input in this case, but also textarea, selects, etc) are save to the POST array (or GET if you set method="GET").
You access the POST and GET arrays from the preview.php page (where you want to print the name in this example) with code like this:
<?php
$name = $_POST['name'];
?>
<p>Hi, my name is <strong><?=$name?></strong>.</p>
in your first page:
<form action="letter.php" method="get">
<input type="text" name="personsName"></input>
<input type="submit" value="submit">
</form>
Then in letter.php do this:
<?php
$firstname = $_GET['personsName'];
echo "My Name is" .$firstname;
?>
That ok? :)