How to take input value from outside form action without javascript? - php

I still in training,
But i stuck in this problem.
// we need this password in 2 form POST
<input style='text' name='password' />
<form action='delete.php' method='POST'>
... // i need password to be here
<input type='submit' name='delete' value='Del' />
</form>
<form action='edit.php' method='POST'>
... // and i need password to be here too
<input type='submit' name='edit' value='Edit' />
</form>
My menthor want to do this using 2 form but I need the input password outside this 2 form.
Are there any way to do this without using script?
I can do this with 1 form and action.php that include 2 php file(edit.php and delete.php)
But he said that it is waste.
Can someone help? I already checking using search engine and found nothing.

Maybe your mentor just testing you on how you solve the situation.. As far as i know... you cant pass value of a textbox upon submit without putting the textbox inside a form.. I just wonder why javascript is forbidden.. Well anyway I suggest you to use 1 form and 1 page for the action and in the action make an if statement to separate you delete and edit method.. maybe in that case it is not waste.. It's just only a suggestion..

Related

PHP not receiving all POST data

I have a really long form, which is basically a sign up for a college. And it's been working fine, although for some reason now I am not able to receive the POST data for the form anymore. I seem to receive all the variables, expect for the 'SUBMIT' button, which is what I look for to find out that it's posted.
It's a sliding form, meaning that it's about 450px high and it is split up into different 'pages', and at the bottom of each page there is previous, save for later, and next buttons. The previous and next activate jQuery functionality which slides the form left or right. The save for later button is a submit button which puts any received data into the database for retrieval later. The HTML for these buttons is:
<input type='button' class='previous' value='Previous'>
<input type='submit' class='saveforlater' name='saveforlater' value='Save For Later'>
<input type='button' class='next' value='Next'>
All three of these buttons work fine, if I test the receiving of saveforlater in PHP like so:
if(isset($_POST['saveforlater'])) {
// Do Stuff
}
It works every time.
However, right at the end of the form I have this:
<input type='button' class='previous' value='Previous'>
<input type='submit' class='next send' name='sendapplication' value='Send Application'>
And It used to work, but I cannot figure out what I've changed in order to stop it working. If I var_dump($_POST), I get all the other variables, except for this button.
So if I try to:
if(isset($_POST['sendapplication'])) {
I get nothing. NOTHING! I don't know why :(. It's such a simple thing and it's frustrating me.
If you click this button, you will see with var_dump or debug() returns this variable.
For submit buttons inside <form>, only buttons clicked will be setted as $_POST variable with its value.
Your input should have the attribute name. Your html should look like
<input type='button' class='previous' name='previous' value='Previous'>
<input type='submit' class='saveforlater' name='saveforlater' value='Save For Later'>
<input name='saveforlater' type='button' class='next' value='Next'>
Your php should look like in /enrol
<?php
var_dump($_POST);
Hope this helps you
How many fields are there in your form??
I think it is the problem due to size of limited post request. It is the problem of server configuration.
If you want to control it refer following link
What is the size limit of a post request?
If you're using a HTML form to send the data and a localhost server, your attribute action needs to have the PHP file directory on the server.

stored the several value of the textbox into an array php

Im making my project, and my project is make a program that will enter name,age and address.
There was a 3 textbox and a submit button. when the user answer the 3 textbox and click submit button, the data or the input of the user will save into an array, but when the user try to input again the previous input will not be replace or it will be there together with the user new inputs, and later those input where use to save into mysql db, do you think this project is possible using php array? i have no sample code because i dont know how to start.thank you so much.
index.php
<form action='index.php' method='get'>
<input type='text' name='name[]'>
<input type='text' name='age[]'>
<input type='address' name='address[]'>
<input type='submit' value='Save'>
</form>
Simple solution is to use 'sticking form' - form elements that stick (keep) the values previously entered.
You can make a textbox sticky like this:
<input type='text' name='name' value='<?php isset($_POST['name'])? $_POST[\'name\']: ""; ?>' />
You need to sanitize the inputs, however, if you try to use it for some real application.

Can I include a forms value into the action redirect in php?

Is it possible in php to include a forms value into the action redirection?
For example:
<form method='POST' name='Select' action='customer.php?CID=xxxxx'>
<input type=text width='5' name='searchVal' />
where xxxxx is the value entered into the form.
I've tried a number of different ways and I'm just not figuring it out! (Still sort of new to php) Any help would be appreciated.
It was looking like I would have to use $_POST and $_GET. A little more information might be in order... customer.php displays a list of customers in order by ID, name, etc. The user currently clicks on the customer ID that they want to display the details for. I'm trying to add a box where they can just enter the customer number to get to the details quickly, but I still want to have the listing displayed. From what it is sounding like, I will have to do this as two separate programs...is that true?
How about this:
<form method='POST' name='Select' action='customer.php'>
<input type='hidden' value='xxxxx' name='CID' />
<input type=text width='5' name='searchVal' />
...
</form>
You are free to add as much hidden values as needed.
Note, that you can even use PHP-like array notation_
<input type='hidden' value='xxxxx' name='CID[1]' />
<input type='hidden' value='yyyyy' name='CID[2]' />
At the PHP-side, access those values using this syntax:
$_POST[ 'CID' ][ 1 ]
$_POST[ 'CID' ][ 2 ]
UPDATE-1
Ah, you want to use a user-entered values to the Action URL just before the form gets submitted?
In this case you need to use JavaScript. Access the DOM to change the Action URL.
But let me ask, why you need to post a form value additionally as a parameter of the Action URL?
UPDATE-2
You wrote: 'From what it is sounding like, I will have to do this as two separate programs...is that true?'
No, actually not. You can still use one customer.php which checks at its beginning, if it was called using a linked customer in the table element or a searched customer in the search field.
In other words: You don't need to prepare two scripts, but two forms for two purposes which call the same script customer.php.
You can include the required value in a hidden field in your form:
<input type="hidden" name="CID" value="xxxxx" />
The reason this is required is that you are submitting the form to your server via POST, but appending parameters to the URL requires submission via the GET method.
Not without a post to the server. The value in the form is filled in client-side, so it has to return to the server before you can add it to the action. (at least, if you want to use php).
You can either
add it after posting (might not be usefull)
use javascript
just not use the GET CID, but get it out of the POST in your customer.php script.
I got it finally! It's actually very simple!
In the body of the code I put this:
<form action='#_SELF' method='GET' name='Projected'>
<input type=text size=5 name='CID' value='' title='Enter Customer number to display' />
<a href='#' onclick='document.Projected.submit();' title='Enter Customer number to display'>Go</a>
And at the top of the code I just do a:
if (!isset($_GET['CID'])) { ...
It works exactly the way I wanted it to!
Thanks everyone for the help! I appreciate it! (And I'm learning more and more about PHP everyday!)
Im pretty sure you cant do that unfortunately

Why is my PHP upload script not working?

I am doing some simple work with uploading a file. I am ignoring error checking and exceptions at this point just to get my uploads working. I have this HTML form:
<form action='addResult.php' method='post' enctype='multipart/form-data' target='results_iFrame' onsubmit='startUpload();'>
Entry: <input type='text' id='entry' />
Stop: <input type='text' id='stop' />
Final: <input type='text' id='final' />
Chart: <input type='file' id='chart' />
<input type='submit' value='Add' /></form>
As you can see, it calls 'addResult.php' within the iFrame 'results_iFrame'. The Javascript is just for animation purposes and to tell me when things are finished.
addResult.php has this code in it (along with processing the other inputs):
$upload_dir = "../img/";
$chart_loc = $upload_dir.basename($_FILES['chart']['name']);
move_uploaded_file($_FILES['chart']['tmp_name'], $chart_loc);
print_r($_FILES);
It uses the 'chart' input from the form and tries to upload it. I have the print_r() function to display some information on $_FILES, but the array is empty, thus making this fail. What could I be doing wrong?
When dealing with forms, the name= is used to reference items serverside, not the id=.
Just change all those id attributes to namess, and you're good to go (hopefully).
You have to give your input elements name attributes or they don't get passed to your script. The id is used for DOM/browser/client-side use.
There might be another problem after you resolve this, but this is a good first step.
Try adding the name attribute to your input values like so:
<input type='file' id='chart' name="myfile"/>
Your inputs have no "name" attribute, only IDs.
You need to give your form fields name attributes

Are inputs in separate forms sent when a submit button is hit?

I'm trying to make a page in php that takes rows from a database, displays them, and then give the viewer a chance to upvote or downvote a specific entry. Here is a snippet:
echo("<form action=\"vote.php\" method=\"post\"> \n");
echo("<INPUT type=\"hidden\" name=\"idnum\" value=\"".$row[0]."\">");
echo("<INPUT type=\"submit\" name=\"up\" value=\"Upvote.\"> \n");
echo("<INPUT type=\"submit\" name=\"down\" value=\"Downvote\"> ");
echo("<form/>\n");
The problem is when I hit a submit button, the value for idnum that gets sent is based on the one farthest down it seems. So my questions is, when a submit button is pressed, are the values for all inputs on a page sent?
Your form tag isn't closed properly. You have <form/>, but it should be </form>.
This makes the entire page a form so it sends all the inputs. With a form that is closed properly though, it will only send the inputs within the form tags that the pressed button was in.
While this wouldn't have helped with this particular issue, I would recommend not mixing your markup with your logic wherever possible. This is quite a lot more readable, and quite a lot more editable as well:
<form action="vote.php" method="post">
<input type="hidden" name="idnum" value="<?php echo $row[0]; ?>">
<input type="submit" name="up" value="Upvote.">
<input type="submit" name="down" value="Downvote">
</form>
Your form is not closed properly. Use </form> instead of <form/>.
The problem with your html is that you should have </form>, not <form/>.

Categories