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

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>

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.

prestashop file upload won't work

I am trying to implement file upload in Order Detail page.
Created form
<form action="" method="post" id="uploadForm" enctype="multipart/form-data">
  <label for="fileUpload">{l s='File to upload:'}</label>
  <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  <input type="file" name="fileUpload" id="fileUpload" />
<div class="submit">
<input type="hidden" name="id_order" value="{$order->id|intval}" />
<input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
<button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
</div>
</form>
and added this to OrderDetailController.php
if (Tools::isSubmit('submitMessage')) {
$idOrder = (int)Tools::getValue('id_order');
$msgText = Tools::getValue('msgText');
if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
{
$this->errors[] = Tools::displayError('Works');
}
...
Now when i submit form - it saves message and completely ignores file.
Does anyone know why?
Solved myself. Answered here
It was ajax issue not sending $_FILES[] data
I'm assuming you placed this into order-detail.tpl of default template.
You put your file input into a separate form that doesn't do anything since it does not have a submit button. The comments form on that page is a completely different one that's why your input is ignored.
What you want to do is place your html code without <form> tags into a proper form that submits message. The form is at the bottom of order-detail.tpl.
<form action="{$link->getPageLink('order-detail', true)|escape:'html':'UTF-8'}" method="post" class="std" id="sendOrderMessage">
<h3 class="page-heading bottom-indent">{l s='Add a message'}</h3>
<p>{l s='If you would like to add a comment about your order, please write it in the field below.'}</p>
<p class="form-group">
<label for="id_product">{l s='Product'}</label>
<select name="id_product" class="form-control">
<option value="0">{l s='-- Choose --'}</option>
{foreach from=$products item=product name=products}
<option value="{$product.product_id}">{$product.product_name}</option>
{/foreach}
</select>
</p>
<p class="form-group">
<textarea class="form-control" cols="67" rows="3" name="msgText"></textarea>
</p>
<!-- Your html snippet -->
<p class="form-group">
<label for="fileUpload">{l s='File to upload:'}</label>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input type="file" name="fileUpload" id="fileUpload" />
</p>
<div class="submit">
<input type="hidden" name="id_order" value="{$order->id|intval}" />
<input type="submit" class="unvisible" name="submitMessage" value="{l s='Send'}"/>
<button type="submit" name="submitMessage" class="button btn btn-default button-medium"><span>{l s='Send'}<i class="icon-chevron-right right"></i></span></button>
</div>
</form>

Pass a input value with url in 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]

Button give $_GET extra parameter

I have two buttons in my form, one is for answer a question and the other is for copy the question.
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<button id="answer" onclick="document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('question').submit()">Copy the question</button>
</form>
The URL of script.php look now like:
script.php?question=sometext
Now I want that when you click at the copy button the URL looks like this:
script.php?question=sometext&copy
And for the answer button:
script.php?question=sometext&answer
EDIT:
There are much answers where is said: "use <input type> instead of <button>"
The problem is that I can't use a input field as button because the button is outside my form. And I can't put it inside my form
What you can do is to use one hidden field and change it's name according to the pressed button. Something like the following:
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<input id="action" type="hidden" name="" value="">
<button id="answer" onclick="document.getElementById('action').setAttribute('name','answer'); document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('action').setAttribute('name','copy'); document.getElementById('question').submit()">Copy the question</button>
</form>
Although this would give you the result you want at the url, it would be more appropriate to have as the hidden's field name the "action" and to change it's value to "copy" or "answer" through javascript.
Try to make two forms, with a hidden input field with the values. Then you get the extra parametrt in your url when submitting
Change your form to the following
<form action="script.php" method="GET" id="question">
<input id="question" type="text" name="question">
<input id="answer" type="submit" name="answer" value="true">
<input id="copy" type="submit" name="copy" value="true">
</form>
url:
script.php?question=hello&copy=true
Then you can check
if(isset($_GET['answer']) && $_GET['answer']=="true"){
//answer action
}
if(isset($_GET['copy']) && $_GET['copy']=="true"){
//copy action
}

Form with two button submit with different value

<form action="here.php" method="POST">
<input type="text" name="text">
<div id="one">
<input type="hidden" name="aaa" value="one">
<input type="submit" value="Send">
</div>
<div id="two">
<input type="hidden" name="aaa" value="two">
<input type="submit" value="Send">
</div>
</form>
Now if i click on Send of div ONE or div TWO i have always in $_POST['aaa'] = 'two';
Is possible make one form with two submit with different values?
If i click on div one submit i would like reveice $_POST['aaa'] = 'one' and if i click on div two submit i would like receive $_POST['aaa'] = 'two'.
How can i make it?
I can use for this PHP and jQuery.
EDIT:
I dont want create two form - i dont want showing two many times <input type="text" name="text">
EDIT: maybe i can instead button submit ? but how?
It seems that what you actually want to do is have a value in each of the buttons, see this, for example:
<form action="demo_form.asp" method="get">
Choose your favorite subject:
<button name="subject" type="submit" value="fav_HTML">HTML</button>
<button name="subject" type="submit" value="fav_CSS">CSS</button>
</form>
You'd need two different forms:
<div id="one">
<form ...>
<input type="hidden" name="aaa" value="one">
<input type="submit" value="Send">
</form>
</div>
<div id="two">
<form ...>
<input ...>
<input ...>
</form>
</div>
Standard practice is that when two fields have the exact same name, to use only the LAST value encountered in the form and submit that.
PHP does have a special-case notation (name="aaa[]") to allow submitting multiple values with the same name, but that wouldn't help you here, as that'd submit ALL of the aaa values, not just the one closest to the submit button.
HTML form:
<form ...>
<input type="text" name="textfield">
<div id="one">
<input type="hidden" name="one_data" value="aaa" />
<input type="submit" name="submit_one" value="Submit" />
</div>
<div id="two">
<input type="hidden" name="two_data" value="bbb" />
<input type="submit" name="submit_two" value="Submit" />
</div>
</form>
server-side:
if (isset($_POST['submit_two'])) {
$data = $_POST['two_data'];
} else if (isset($_POST['submit_one'])) {
$data = $_POST['one_data'];
} else {
die("Invalid submission");
}
Instead of showing two submit button, you can show a radio list with two options and one submit button.
Try this:
in html-
<input id="PreviousButton" value="Previous" type="submit" />
<input id="NextButton" value="Next" type="submit" />
<input id="Button" name="btnSubmit" type="hidden" />
in jOuery-
$("#PreviousButton").click(function () {
$("#Button").val("Previous");
});
$("#NextButton").click(function () {
$("#Button").val("Next");
});
then you can see in the form results - what "Button" contains.

Categories