HTML only posts last text box for text form - php

Here is my HTML code:
<form name="candidates" action="candidate_thankyou.php" method="post">
<div class="wrap">
<div class="position"> President: <br> </div>
<input type="text" name="president"> <br>
<input type="text" name="president"> <br>
<input type="text" name="president"> <br>
</div>
<div class="wrap">
<div class="position"> Vice President: <br> </div>
<input type="text" name="vp"> <br>
<input type="text" name="vp"> <br>
<input type="text" name="vp"> <br>
</div> ...etc
<input id="submit" type="submit" value="Submit">
</form>
However, when I call var_dump($_POST) in my php file, I only get the last text box value for each input name (eg "president" or "vp"). If I only use the first 2 text boxes, I get an empty string. How can I get all three values from the form?

Form fields are identified by their name. You're overriding the fields president/vp every time, that's why you only get the last field's values. You can send it as an array like this:
<input type="text" name="president[]">
<input type="text" name="president[]">
..

Field name must be either unique (president1, president2, etc.) or an array president[].
Further handling depends on which method you choose. Second method is well described in HTML form input tag name element array with JavaScript

You should have seperate names for each input or add [] to the end of the names to add them to an array. Ie
name="vp[]"

Related

How to display text from current web address after submitting php form

How to display text from current web address after submitting form
www.example.com/?n=Example-Text
<form method="post" action="/submit.php">
<div class="enter-name">
<input class="animated pulse infinite" type="name" required="" maxlength="50" name="n" placeholder="Enter Your Text Here">
<button class="btn" type="submit"><span>></span> Go</button>
</div>
</form>
If you want to show the text from input name="n" ,
make the form method GET <form method="get" action="/submit.php">
and in your submit.php
<?php
echo $_GET['n'];
?>
You are asking about a GET request when you code has a response that is a POST response as indicated in the form tag <form method="post" action="/submit.php">
For the example you gave, the submit.php page would need to have the following code
<?php echo $_POST['n']; ?>
This will display inline the value that is in the name="n" input once submitted via the form.
if you want to see the information that is being passed to the submit.php file in the url then you need to change the HTML to use a get method for the form instead of the post that it currently uses
<form method="post" action="/submit.php">
<div class="enter-name">
<input class="animated pulse infinite" type="name" required="" maxlength="50" name="n" placeholder="Enter Your Text Here">
<button class="btn" type="submit"><span>></span> Go</button>
</div>
</form>
You have to set get method instead of post,
get passes parameters to url, is called urlencodded,
<form method="get" action="/submit.php">

Fetching result from another website using html

I have created a simple page with 3 text boxes and three check boxes in it. What I actually want to do is; Now consider that we have a student data page called "A" and the page I have created is "B".
Assume that I entered the first name and last name in "B"(which is the page we are going to create); the first name and last name should be taken to page "A"(site from where we want result. It should be auto-filled and once the result come(I actually mean when the next page opens). a screenshot of the page should be taken and saved in a particular location.
The location is like D:\REPORT\student 1
All the screenshots must be save here
The three check boxes are three different sites. I should be able to get the result from one or more of those three sites
This is the code that I have coded.
<html>
<center><font size="24" color="White"><b>
Experiment 1</center></font></b></i>
<body bgcolor="600000" bgproperties="fixed">
<br><br><b><font color="White">
First Name:<br>
<input type="text" name="fn"><br><br>
Last Name:<br>
<input type="text" name="ln"><br><br>
File Stored Location<br>
<input type="text" name="fsl"><br><br>
<form>
<input type="radio" name="site1" value="site1"> site1 <br>
<input type="radio" name="site2" value="site2"> site2<br>
<input type="radio" name="site3" value="site3"> site3<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Is this possible?
First of all, consider using CSS for your layout. It's much cleaner then what you are using now :).
Wrap everything in a form like so:
<html>
<center><font size="24" color="White"><b>
Experiment 1</center></font></b></i>
<body bgcolor="600000" bgproperties="fixed">
<br><br>
<form action="a.php" method="POST">
<b><font color="White">
First Name:<br>
<input type="text" name="fn"><br><br>
Last Name:<br>
<input type="text" name="ln"><br><br>
File Stored Location<br>
<input type="text" name="fsl"><br><br>
<input type="radio" name="site1" value="site1"> site1 <br>
<input type="radio" name="site2" value="site2"> site2<br>
<input type="radio" name="site3" value="site3"> site3<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Then you need php in your a.php to collect the post data from your form.

Submit button, next step

I am done with the search page where the user enters the information and select from the drop-list. I've also added the button AddList where you can have more than one search form with tag names changed. All of the searches will eventually be executed in one Submit button and each search will go in one single query. My table caries all the information and tuples contain only numbers.
UPDATED: I tried changing the input type of the input tags but the enable and disable functions can't seem to work on integers, only on text fields. How can I fix that?
My submission is tomorrow, and here is my search code:
<script type="text/javascript">
$('#exactButton').live('click', function(){
$(this).prev().prev().prev().prev().prev().removeAttr('disabled');
$(this).prev().prev().prev().attr('disabled',true);
$(this).prev().prev().prev().prev().attr('disabled',true);
});
$('#rangeButton').live('click',function(){
$(this).prev().prev().removeAttr('disabled');
$(this).prev().prev().prev().removeAttr('disabled');
$(this).prev().prev().prev().prev().attr('disabled',true);
});
})
</script>
And this is my HTML code:
<button id="button">Add List</button><br><br>
<form id ="form" name="search" method="get" action="test.php">
<div id="div">
<select name ="select" >
...options...
</select>
Value:<input type="text" name="exact" id="exactField" />
From: <input type="text" name="from" id="fromField" />
To: <input type="text" name="to" id="toField" />
<br>
<input type="button" name="answer" value="Range" id="rangeButton" />
<input type="button" name="answer" value="Exact" id="exactButton" />
</div>
<br>
<input type="submit"name="search" value="Submit">
</form>
Thank you in advance..
as Dagon said, you will see all submitted parameters in the URL since you are submitting the form with method GET. here is very good explanation for this: http://www.w3schools.com/php/php_get.asp
One idea:
add some custom attributtes to the elements (to the clones too).
this.attr("mycustomattribute","somevalue");
after this, you can get all elements on the page with your custom attribute and your value.
divs = $('div[mycustomattribute="somevalue"]'); //should give all div container with attribute "mycustomattribute" with value "somevalue"
divs.each(function(){
console.log(this,$(this).attr('name'));//show expression (for debug)
});
then you can collect this elements, serialize it and add it to your post Not tested, but an idea.
Kind Regards
In PHP, it's already there.
print_r($_GET); will list all parameters sent by GET method
print_r($_POST); will list all parameters send by POST method.
Then, of course, you will need to iterate in the array to include each values in your query statement.
You can naming input with prefix or suffix correspond to sequence that user click to add list and add those set of inputs to only form.
<form id ="form" name="search" method="get" action="test.php">
<div>
<select name ="select[1]" >
...options...
</select>
Value:<input type="text" name="exact[1]" class="exactField" />
From: <input type="text" name="from[1]" class="fromField" />
To: <input type="text" name="to[1]" class="toField" />
<br>
<input type="button" name="answer[1]" value="Range" class="rangeButton" />
<input type="button" name="answer[1]" value="Exact" class="exactButton" />
</div>
<div>
<select name ="select[2]" >
...options...
</select>
Value:<input type="text" name="exact[2]" class="exactField" />
From: <input type="text" name="from[2]" class="fromField" />
To: <input type="text" name="to[2]" class="toField" />
<br>
<input type="button" name="answer[2]" value="Range" class="rangeButton" />
<input type="button" name="answer[2]" value="Exact" class="exactButton" />
</div>
.
.
.
<br>
<input type="submit"name="search" value="Submit">
</form>

How to pass the data in the input type using php

Hi, I want to know how to pass the data into the input type field; I'm using only $_POST method and also I did not use the database first. Please help.
form.php
<form action="booking.php" method="post">
<p>
I want to be pick up at:
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="pickupplace" id="pickupplace" autocomplete="off" tabindex="1" style="width: 260px;"/>
</p>
<p>
drop off at
</p>
<p>
<input placeholder="Enter Address, Airport, Landmark" type="text" name="dropoff" id="dropoff" autocomplete="off" tabindex="2" style="width: 260px;" />
</p>
</form>
in the booking.php
<div>
<p>From</p>
<p>
<p>
<?php
if(isset($_POST['pickupplace']) == NULL){
echo "-";
}
else{
echo $_POST['pickupplace'];
}
?></p>
</div>
in the edit_ride.php
<div>
<p>From</p>
<p>
<input type="text" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>
</p>
</div>
i want to pass the data into the edit_ride.php in the input type please help here it is,
What you can do is, you can merge edit_ride.php and booking.php, so that directly you can display the values using
<input type="text" name="pickupplace" value="<?php echo $_POST['pickupplace']" placeholder="Enter Address, Airport, Landmark"/>
This may not be the only solution, as some time we need multiple pages, in that case you may consider sessions or cookies also.
Alternatively, you can pass the values from one page to another using querystring ($_GET) method also without submit the forms in internal pages.
why are you specifying the form action booking.php if you need to submit your data on edit ride.php
so first of all change the form action to edit_ride.php and then recieve the data in your textbox as following on the page edit_ride.php
<input type="text" value="<?php if(isset($_REQUEST['pickupplace'])) echo $_REQUEST['pickupplace']; ?>" name="pickupplace" placeholder="Enter Address, Airport, Landmark"/>

Showing form data after submit

I have a form with a submit button and a handler that stores data in the database. Problem is when the form is submitted, all data is cleared from the input fields. Is there a way to still show them after submit? What changes do I need to make to my form_submit function?
function mymodule_form_submit($form, &$form_state) {
//how to retain the input in the form
}
I'm looking for the most "drupalish" way to get this done?
As indicated by this previous StackOverflow question you can accomplish this with $form_state['storage'] and $form_state['rebuild'].
You can access the data using $_REQUEST['form_variable_name'] where form_variable_name is the name of the html input tag.
You then need to render the page back putting this value into the input tags value field.
<form method="POST" action="/account/contactdetails/">
<div>
<label>First name:</label>
<input type="text" name="firstname" value="<?php echo $_REQUEST['firstname']; ?>" />
</div>
<div>
<label>Last name:</label>
<input type="text" name="lastname" value="<?php echo $_REQUEST['lastname']; ?>" />
</div>
<input type="submit" value="Save" />
</form>

Categories