Pass a input value with url in php - php

I want to pass a input value with a url.
<div class="modal-body">
<div id="myDiv" class="answer_list">
<form action="" id="usrform" method="get">
<textarea name="comment" style="width: 450px; height: 80px; form="usrform"></textarea>
<?php echo '<a href="reject_request.php?leave_id='.$id1.'&emp_id='.$emp_id.'">'?>
<button style="float: right" type="button" class="btn btn-primary" name="submit">
Proceed
</button></a></form></div>
</div>
Here I want to pass the textarea input value to 'reject_request.php' page with other variables. I couldn't able to find a way, Can any one help me !

Use method="POST" and action="reject_request.php"
<form action="reject_request.php" id="usrform" method="POST">
<textarea name="comment" id="comment"></textarea>
<input type="hidden" name="leave_id" id="leave_id" value="<?php echo $id1; ?>">
<input type="hidden" name="emp_id" id="emp_id" value="<?php echo $emp_id; ?>">
</form>
In reject_request.php you can access the form datas via $_POST['comment'],$_POST['leave_id'],$_POST['emp_id']

First of all, it is not advisable to pass long content in URL, as commented by #Dhara Parmar.
But if you want to do it,
<form action = "yourpage.php" .... as, again, commented by splash 58
As far as accessing those variables are concerned, you can access them via ASSOCIATIVE GLOBAL ARRAY $GET[KEY]

Related

unable to get value of form with $_post

i want to get value of input of my form via $_post in my insert page but my problem is that i get error massage:undefined index:track_code and i cant get value of it.the names is same what is problem?
this is my problem why stackoverflow want more detail. this is all detail
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<form action="insert.php" method="post" class="form-horizontal form-checkout">
<div class="control-group">
<label class="control-label" for="firstName">نام<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="first_name" type="text" id="firstName" class="span4" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="lastName">نام خانوادگی<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="last_name" type="text" id="lastName" class="span4">
</div>
</div>
<input name="submit" type="submit" class="btn btn-success" value="خرید" style="width: 66px"/>
</form>
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<?php
$track_code = $_POST['track_code'];
?>
Set this one code in your form
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo ($track_code_rnd)?$track_code_rnd:'';?>" style="width: auto;height: auto" disabled />
</form>
Remove disable tag from your input code. Disable controls wont be posted on server. for that you can make it readonly or make it hide
Try Putting the PHP code on the form. as given below.
<?php
if (isset($_POST['submit'])) {
$track_code = $_POST['track_code'];
}
?>
<form action="your_page.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd; ?>" style="width: auto;height: auto" readonly />
<input name="submit" type="submit" />
</form>
It will execute the whole file as PHP. The first time you open it, $_POST['submit'] won't be set because the form has not been sent. Once you click on the submit button, it will print the information.
Disabled controls never post on server. So make it readonly or hidden.

Pass variables to another php page using a button

So if someone is logged in my script reads the values and stores it and sets it as variables then I'm trying to make a registration page for something that members can register in.
The script is simple
<div id="english1"><p id="english1p">تأكد من بياناتك ثم اضغط رز الموافقة</p><br>
<form class="register2" action="includes/register2.inc.php" method="post" name="register2form"
<p class="username">اسم المستخدم: <?php echo htmlentities($_SESSION['username']); ?></p>
<p class="email">الايميل: <?php echo htmlentities($_SESSION['email']); ?></p>
<p class="age">السن: <?php echo htmlentities($_SESSION['age']); ?></p>
<p class="coursetype">الكورس المراد التسجيل فيه: <?php echo $coursename; ?></p>
<p class="paymethod">طرق الدفع:</p><ol><li>طريقة</li>
<li>طريقة</li>
<li>طريقة</li>
</ol>
<p class="sure">للتأكيد اضغط تسجيل</p>
<input class="register2button"
type="button"
value="تسجيل"
onclick="" />
</div>
Ignore the letters you don't understand, it's arabic.
So the script reads variables and then I want when the member clicks the submit button, the page POST the variables to includes/register2.inc.php without input as the variables are already set.
How can I do that?
If you want to keep your <p> tags you can store all the variables you want to pass to the next page in <input type="hidden" value="some value" /> These boxes will not be shown on the page, but will pass along data with any request you send to your server.
You can store your value in hidden element and pass it to next page.
<form action="page name" method="post">
<input type="hidden" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>" />
<p class="username"> username : <?php echo htmlentities($_SESSION['username']); ?></p>
<input type="submit" name="submit" value="submit" >
</form>
Inside the form, instead of p you should use input for each parameter:
<input type="text" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>"/>
You can kept this input hidden also like:
<input type="hidden" name="username" value="yourvalue"/>
These input field value won't pass in next page in $_POST if you will use p you have to use input for this.

Empty $_POST in Wordpress Archive Page

I have a custom form in my wordpress theme archive.php file but I can't get the post of that form. It's empty.
I have these:
<?php print_r($_POST); ?>
<div class="filtros">
<h3>Búsqueda de documentos</h3>
<form action="#" method="post">
<input type="text" id="name" name="f_name" placeholder="Buscar" value="<?php echo $_POST['f_name']; ?>" />
<div class="dates">
<input type="text" id="inicio" class="date" name="f_inicio" placeholder="Fecha de inicio" value="<?=$_POST['f_inicio']?>" /> /
<input type="text" id="final" class="date" name="f_final" placeholder="Fecha final" value="<?=$_POST['f_final']?>" />
</div>
<div class="submit"><input type="submit" value="Buscar" /></div>
</form>
</div>
Even if I pass the variables throw the URL I cant get that vars with $_GET.
¿Any idea?
While it's not advisable from a security point of view, you can change the method on your form from method="post" to method="get" to have variables posted as $_GET variables instead.
Change action="#" to action="<? echo $_SERVER['REQUEST_URI']?>"
Try change <?= to <? echo
You may need to point the action="myfile.php" to specific file.. See the solutions here:
$_POST returns empty on form submit in wordpress

Can't retrieve values from other page (Stored As Label)

I am new to PHP and I am trying to get information from a form to another page, but the data won't transfer over when I hit submit. What am I doing wrong? Should I be trying to use GET instead of POST? What is the best way to debug something like this?
The path to information.php is definitely correct.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label name="tempID"><?php echo $number; ?></label>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
This file is in a different page (information.php)
if (isset($_POST["tempID"]))
{
$infoID = $_POST['tempID'];
}
echo $infoID;
<input type="hidden" name="tempID" value="<?php echo $number; ?>" />
Add this next to your original echo, post variables can't be stored in a label. Also remove the name value from the label
You need a submit input instead of a button with the name submit. Change the button's html to:
<input type='submit' value='More Details'>
Change Label in input
<form action="information.php" method="post">
<div class="row" style="padding-bottom: 20px;">
<input name="tempID" value="<?php echo htmlentities($number); ?>"/>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
labels are only to display information. they are not submitted during form submission.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label>Number:</label>
<input name="tempID" value="<?php echo $number; ?>"/>
<input class="btn" id="submit" name="submit" type="submit" value="More Detail" />
</div>
</form>

PHP form - Processing Textfield isn't working

I am currently trying to make a form validation which checks wether some inputs / a textfield are empty or not. I want the text in a textfield to be saved and entered in the next php file in the textfield again. It works with all inputs but not with the textfield. The site loads but the textfield is just empty.
THank you in anticipation!
HTML PART:
<form id="formularheader" name="form" method="post" action="php/contact.php">
<fieldset id="personenInfo">
<p><label for="message" >Nachricht *</label></p>
<p><textarea name="nachricht" id="message" cols="40" rows="10" required=""></textarea></p>
<div class="terms">
<input type="checkbox" name="terms">
</div>
<p style="font-size: 80%; color: #292929; font-style: italic;">* notwendige Angaben</p>
</fieldset>
<input type="submit" id="submitButton" value="Abschicken">
</form>
PHP PART:
<?php
$message = $_POST['message'];
?>
<form id="formularheader" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<fieldset id="personenInfo">
<p><label for="message">Nachricht *</label></p>
<p><textarea name="nachricht" id="message" value="<? echo $message; ?>" cols="50" rows="10" required=""></textarea></p>
<div class="terms">
<input type="checkbox" name="terms">
</div>
<p style="font-size: 80%; color: #292929; font-style: italic;">* notwendige Angaben</p>
</fieldset>
<input type="submit" id="submitButton" value="Abschicken">
</form>
should be $_POST["nachricht"] (name attribute is taken in account when in a POST)
You need to use the field name as opposed to the ID e.g. $_POST['NAME'] whereas you have $_POST['id']
More than one level of validation can be used:
use the HTML5 tool : add required to each input to deny the user from sending empty input
use if(isset())

Categories