How do you use php?email=# to retrieve record - php

In abc.php, i have a form whose action is xyz.php. I want $email=$POST['txtEmail'] to be used in xyz.php
To do that, I typed: <form id="form1" name="form1" method="post" action="xyz.php?<?php $email=$_POST['txtEmail']; ?>">
Is this the correct way to do it?
EDIT
abc.php
<form id="form1" name="form1" method="post" action="xyz.php">
<input name="txtEmail" type="text" size="30" />
<input type="submit" name="Submit2" value="Submit" />
</form>
xyz.php
<form id="form1" name="form1" method="post" action="def.php">
<input type="text" name="txtAns" />
<input type="hidden" name="txtEmail" id="txtEmail" value="<?php echo $_POST['txtEmail']; ?>" />
<input type="submit" name="submitEmail" value="Submit" />
</form>
def.php
$email=$_POST['txtEmail'];

Edited
In abc.php:
<form id="form1" name="form1" method="post" action="xyz.php">
<input type="text" name="email" id="email" />
</form>
In xyz.php
<form id="form2" name="form2" method="post" action="def.php">
<input type="hidden" name="email" id="email" value="<?php echo $_POST['email']; ?>" />
</form>
In def.php
$email = $_POST['email'];
Is that what you're after?

Related

On form submit, pass email address from first form to second form

I have two forms, the first gets submitted then the page reloads and shows the second. The problem I have is passing the email address from the first form to the second one. What's the best way to do this without interfering with my actions or changing it from POST to GET?
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>
1) Add a hidden field to the second form.
2) Add the value of the email address (submitted from the first form) to the hidden field when rendering the second form.
e.g.
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="hidden" name="email" value="<?php echo $_POST["crowd_email"]; ?>" />
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>
That way, when you submit the second form, the email field will be submitted along with the rest of the new data.
You can just add a hidden input in the second form containing the email value and give it the value from the first submission
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<!-- New line to hold the email invisbly -->
<input type="hidden" name="crowd-email" value="<?php echo $_POST['crowd_email']; ?>"/>
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>

Double Get Send Data

In this page : page.php?id=value
I've this html's code:
<form action="" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
It's redirect me to: page.php?key=value , i want to redirect to: page.php?id=value&key=value , how i can do it? I must redirect it to this page with PHP ?
simply,
<form action="page.php" method="get">
<input type="hidden" name="id" value="<?php echo $value ?>">
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
You can have the id as a hidden input in your form
<form action="" method="get">
<input type="hidden" value="<?php echo $my_id; /*Suppose this variable contain your value */ ?>" name="id" />
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
put everything you want on the next page in your form:
<form action="page.php" method="get">
<input type="text" name="id" value="<?php echo $_REQUEST['id'];?>" />
<input type="text" name="key" />
<input type="submit" name="send />
</form>
Really though, you should be using POST to send data, and the above code is NOT secure (allows anything in a url to easily end up in a form that could create some sql injection or XSS type issues.
You need to have the form's action set to the page you want it to submit to. If it is blank it will just submit to the same page.
<form action="page.php?id=value&key=value" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>

How to keep form data even after submiting not to dispear

In this
<form method="POST" action="">
<input type="text" class="field small-field" name="tex1" />
<input type="submit" value="search" name="search"/>
<input type="submit" value="print" name="print"/>
</form>
After I submit the form, the page refreshes and the data inside the input texts gets blank
Is it possible to keep the data even after submit?
Regards.
You can simply use ajax for submitting the form.
Or use following
<form method="POST" action=""><input type="text" class="field small-field" name="tex1" value="<?php (isset($_POST['text1]))? echo $_POST['text1] : '';" /><input type="submit" value="search" name="search"/><input type="submit" value="print" name="print"/></form>
try to echo, what ever is the variable named for your input.
<form method="POST" action="">
<input type="text" class="field small-field" name="tex1" value="<?php echo $_POST['tex1'];?>" />
<input type="submit" value="search" name="search"/>
<input type="submit" value="print" name="print"/>
</form>
With php for example:
<form method="POST" action="">
<input type="text" class="field small-field" name="tex1" value="<?php echo $_POST['tex1']; ?>"/>
<input type="submit" value="search" name="search"/>
<input type="submit" value="print" name="print"/>
</form>
If you are handling the post on the same page you could just do like this on the fields where you want the posted value to be shown:
<input type="submit" value="search" name="search" <?php if( isset( $_POST['search'] ) ){ echo "value=\"". $_POST['search'] ."\"; } ?>/>
Use this:
<form method="POST" action="">
<input type="text" class="field small-field" name="tex1" value="<?php if(isset($_POST['tex1'])) echo $_POST['tex1'] ?>" />
<input type="submit" value="search" name="search"/>
<input type="submit" value="print" name="print"/>
</form>
Bascially http is statelessprotocol , hence you need to save the data some where
The simplest way in this case would be to use a conditional operator
<input type="text" class="field small-field" name="tex1" value="<?php echo (isset($_POST['search'] || $_POST['search'] )?$_POST['tex1']:''); ?>" />

Add suffix to action url

I have this form
<form role="search" method="get" id="searchform" class="searchform" action="http://search.site.com/Archive/search/read" >
<div>
<input type="text" value="" placeholder="text" name="query" id="?" />
<input type="submit" id="searchsubmit" value="." />
</div>
</form>
I need to add this suffix at the end of the url: &title=&start_year=&end_year=
For example:
http://search.site.com/Archive/search/read?query=pertini&title=&start_year=&end_year=
Where the query is: pertini
Is it possible in JavaScript or jQuery or in PHP?
Site only support GET method.
I am working in WordPress.
Just add hidden fields for all the ones you need:
<form role="search" method="get" id="searchform" class="searchform" action="http://search.site.com/Archive/search/read">
<div>
<input type="text" value="" placeholder="text" name="query" id="?" /><input type="submit" id="searchsubmit" value="." />
</div>
<input name="title" type="hidden" value="" />
<input name="start_year" type="hidden" value="" />
<input name="end_year" type="hidden" value="" />
</form>

HTML input field jumps

I have 2 text fields, user and password. When I enter the password, it jumps to the first one. I have no idea why that is happening. I couldn't find why it is jumping. How do I change it so the password form doesn't jump? Here is the code:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
You have both of the inputs wrapped in one label. The browser is getting confused and it thinks that that entire content is a label for the first input (that's how labels work, apparently). You should only use <label> to wrap text for input.
This:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
Should be this:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />

Categories