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.
Related
I have a very simple form like I've done dozens, but this one isn't working for a reason that eludes me.
When var_dumping the $_POST variable after submit it's empty but it's working on the request_maker from chrome.
here is where it is submited:
echo " <form method='POST'>
<input type='button' class='button' style='height:50px' name='manage' value='export' onclick='submit()'/>
</form>";
var_dump($_POST);
the var_dump returns an empty array.
From other subjects I've seen they talk about php.ini wich was unchanged since a long time on my side, no updates were made, and others post requests on different pages are working
The problem is that you are not POSTing the form when you press the button. You are performing the onclick event.
Remove the onclick attribute (or make sure that the submit() function is POSTing).
var_dump($_POST)
Only works when you submit form. so change code as mention below you will able to dump data
if(isset($_POST)){
var_dump($_POST);
}
also put action in form Tag
action="<?php echo $_SERVER['PHP_SELF']; ?>"
Other Thing try put Input field to get clear idea
<input type="text" name="name"><br>
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..
I thought of making something that generates lots of form dynamically and then using jquery to handle their submission.
So i generate the form using php by using something like this.
while(some condition) {
echo "<form method=post action=specific_url.php name=some_form_name>";
echo "<input type=text>";
echo "<input type=submit>";
echo "</form>";
}
Well the above is just a skeleton. The main Problem is how should i name/id the form elements so that i can uniquely identify each form during submission and submit them, and use can extract the data at the specific_url page without any problem.
A direct analogy of this feature that i can think at the top of my head is that of facebook posts, where each post has got a comment box.
UPDATE
I guess i wasn't very clear with the question. Sorry about that. Let me rephrase it.
So till now, I have these dynamically generated forms. Now suppose user writes in one of the textbox and click on submit button.
At these point jquery should take control of it. Send that particular form data to the url. Retrieve the result and do something.
So in the end, I should be able to do something like this
$(some_selector).submit(function(e) {
e.preventDefault();
$.post('specific_url.php',$(some_selector).serialize(),function(data) {
// some stuff
});
});
Here "some_selector" is that selector which gets activated when a particular form is submitted and then sending that form's data.
You can use a hidden form element and set its value to an id for the form.
<input type="hidden" name="form_id" value="1">
This way you can access the form_id like any other form value once you submit it. I am looking at the facebook source now and I see a few hidden form elements next to the comment boxes
It is a requirement that the element id attribute is unique, not so with the name attribute.
It is also possible to use arrays of elements, for example :
<input name="comment[]" type=text>
<input name="comment[]" type=text>
<input name="comment[]" type=text>.
In your PHP. the value of $_POST['comment'] will be send as an array.
If you want to uniquely identify each comment in your PHP code, you will be forced to rename them uniquely.
<input name="comment1" type=text>
<input name="comment2" type=text>
<input name="comment3" type=text>
Since you are generating the form using PHP, this would be easy to keep track of the name that should be generated.
If you have multiple forms, you have free reign, sort of. There is no need a name for the form. However, to identify where in the page the form is places, place a hidden field.
while(some condition) {
echo "<form method=post action=specific_url.php";
echo "<input name='position_in_page' type='hidden' value='$somevalue'>";
echo "<input name='comment' type='text'>";
echo "<input type='submit'>";
echo "</form>";
}
I have a form on a page that is used to "Add/Edit a Location". Here is my form:
<form id='locationEditForm' name='locationEditForm'>
<table width='50%'>
<tr><td colspan='2'><hr></td></tr>
<tr><td colspan='2'><button type='submit' name='save' id='save'>Lookup Location By ID: </button>
<input type='text' size='10' name='locationToEdit'><br/><br/></td></tr>
<tr><td>Name:</td><td><input type='text' name='locationName'/></td></tr>
<tr><td>URL:</td><td><input type='text' name='locationURL'/></td></tr>
<tr><td>Coordinates:</td><td><input type='text' name='locationCoords'/></td></tr>
<tr><td>Address:</td><td><textarea name='locationAddress' rows='4' cols='40'></textarea></td></tr>
<tr><td>Phone:</td><td><input type='text' name='locationPhone'/></td></tr>
<tr><td>Hours:</td><td><textarea name='locationHours' rows='3' cols='40' wrap='soft'/></textarea></td></tr>
<tr><td colspan='2'><button type='submit' name='save' id='save'>Save Changes</button>
<button type='button' class="cancel">Cancel</button></td></tr>
</table>
</form>
I've wrapped the form elements in a table just for the sake of keeping the input boxes aligned for now in a "quick and dirty" sort of way.
Anyway, As you can see, I have a button and input area for the user to "lookup" an existing location by id. This is so that an existing location can be edited. I understand how to make that button 'submit' to my php code and to then lookup the location in the database, but my question is this -- is it possible to lookup the location in a MySQL database and load the information into the existing form without causing the page to reload as it normally would when I post the form?
Ideally, I imagine the data for an existing location just "popping" into the form without the entire page reloading. How would I go about doing something like this?
Thanks a ton!
The technique you're looking for is commonly referred to as Ajax. In your case, you'd want to submit an XMLHttpRequest() to a different PHP script which returns data you can use. Either HTML to insert into your form, or JSON data which you parse and use to update field values would be good choices.
There are lots of resources out there on how to make a PHP/MySQL endpoint for an Ajax request. These search terms should get you started. Good luck!
Indeed it is, you have to use javascript though. I would advise you to take a look at Jquery. And it's $.ajax and $.post functions.
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