Form not passing the values - php

I am creating a php appointment calendar. I am using the following code to print calender days. Upon clicking on a day, the concerned input values should be passed to a php file. but its not posting. Im getting undefined index variable error. whats wrong with my code.
$calendar.= '<form name="'.$list_day.'" action="touch.php" method="post">
<input type="hidden" name="reg_no" value="'.$reg_no.'" disabled/>
<input type="hidden" name="exe_name" value="'.$exe_name.'" disabled/>
<input type="hidden" name="mobile" value="'.$mobile.'" disabled/>
<input type="hidden" name="company" value="'.$user_data['company'].'" disabled/>
<input type="hidden" name="division" value="'.$user_data['division'].'" disabled/>
<input type="hidden" name="s_date" value="'.$complete_date.'" disabled/>
<div class="day-number1" align="center"> <input name="'.$list_day.'" type="submit" value="'.$list_day.'"/></div>
</form>';

The disabled inputs are not passed. Remove disabled property for your inputs.

Related

PHP $_POST is empty when posting hidden fields

I have the following form that is dynamically generated:
<form action="index.php?route=module/print_wizard/showPrintSheet&token=4ef5f4af6ba25d6096357fdb4809e819" method="post" enctype="multipart/form-data" id="form">
<input name="[print][6][1]" type="hidden" value="on">
<input name="[print][6][3]" type="hidden" value="on">
<input name="[info]" type="hidden" value="INV-GIS-00002-3">
<input name="[layout_override][6][1]" type="hidden" value="">
<input name="[layout_override][6][3]" type="hidden" value="">
<input name="[bundle_override][6][1]" type="hidden" value="">
<input name="[bundle_override][6][3]" type="hidden" value="">
<input name="[run_id]" type="hidden" value="14040455">
<button type="submit">Export</button>
</form>
My PHP code is:
var_dump($_POST);
echo "<HR>".$this->request->server['REQUEST_METHOD'];
I have done this a million times before and can not for the life of me figure out why my $_post array is empty. I have changed my post to a get and all the fields and values are passing, but I need to use a post. Do I need to have one visible form element? Please help!
You are not using valid names for your form fields:
<input name="[print][6][1]" type="hidden" value="on">
is not valid as it just has an array index but no name.
If you change it to for example:
<input name="print[6][1]" type="hidden" value="on">
it will work without any problems.

PHP Form URL vars

I was wondering if it would be possible to have a variable in the URL created when submitting a form?
form:
<form class="register_form" action="action.php" method="get">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
I'd like the link to end up as: http://.../action.php?do=register
My reasoning for this is so that I can use action.php for more than one thing using if statements. Thanks ^^
Just append the variable you want to the action link.
<form class="register_form" action="action.php?do=register" method="get">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
Or you can add a hidden field to your form:
<input type="hidden" name="do" value="register" />
Sure, the form action URL can have a query string:
<form class="register_form" action="action.php?do=register" method="POST">
The form data will be sent via POST but do will still be available via GET.
You need to add this to the form
<input type="hidden" name="do" value="register">
Yes, it is possible. You can use any one of following methods
1) You can set the name of your submit button "do"; As the value of your submit button is "Register"
<input type="submit" name="do" value="Register" />
OR
2) You can add a hidden field to your form
<input type="hidden" name="do" value="register" />

WordPress and GET

I'm having form and page(Template Page) in WP. Through form, I want send values GET, then the page create query.
form:
<form id="homepage_form" method="get">
<input type="hidden" name="p" value="48" />
<input class="first" type="text" name="name" />
<input type="text" name="location"/>
<select name="category">
<option value="0" disabled selected>Kategori</option>
</select>
<input class="btn" type="submit" value="Search" />
</form>
First Question. Do I need send id page in form?(input type="hidden" name="p" value="48"). Maybe is other method.
Second Question. When I sent this form, I saw "page_id_48/?location=asdasd". WP stolen second GET (name).
Now I know... I don't like forms in WP or I don't understand.
you need the attribute value , in order to GET it.
<input class="first" type="text" name="name" value="something" />
In WP can't to send get 'name'
<input class="first" type="text" name="name" />
<- bad
<input class="first" type="text" name="notname" /> <- ok

Form data not passing to PHP

I have what should be a simple form to pass data to a php page. The form is:
<form action="php/setlist.php" method="post">
<input type="text" id="SetListName" />
<input type="hidden" id="newList" name="newList" value="" readonly="readonly" style="border: none;">
<input type="submit" style="width:150px;"><br /><br />
and the php is:
$SetListSave = $_REQUEST['newList'];
$SetListName= $_REQUEST['SetListName'];
echo $SetListName;
echo $SetListSave;
I am getting the newList from the form just fine but the SetListName isn't getting passed. I am a novice with php so I could be missing something basic here, but I am stumped.
You are missing name attribute in:
<input type="text" id="SetListName" />
Replace
<input type="text" id="SetListName" />
with
<input type="text" id="SetListName" name ="SetListName"/>
You need to have a 'name' attribute in the form for each input field that you want to read in PHP. So you're code should read:
<form action="php/setlist.php" method="post">
<input type="text" id="SetListName" name="SetListName"/>
<input type="hidden" id="newList" name="newList" value="" readonly="readonly" style="border: none;">
<input type="submit" style="width:150px;"><br /><br />
use
<input type="text" id="SetListName" name="SetListName" />
you have not used name attribute

Multiple $_POST on same page PHP

I have a question.
Currently this form will be dynamically generated.
Example,
<form method="POST">
<input type="text" name="location" id="location1" />
<input type="submit" value="Submit!" />
<input type="text" name="location" id="location2" />
<input type="submit" value="Submit!" />
<input type="text" name="location" id="location3" />
<input type="submit" value="Submit!" />
<input type="text" name="location" id="location4" />
<input type="submit" value="Submit!" />
</form>
So whenever i press submit, it will take last value of form only. How do i make it take all $_POST?
Thank you.
You could give each field a unique name: location1, location2....
Alternatively, you could build an array.
To do that, add a [] to each element's name:
<input type="text" name="location[]" id="location1" />
this will give you an array in $_POST["location"].
Don't forget that before using the data (e.g. in a database query or page output) you will need to sanitize each array element separately (using mysql_real_escape_string() or htmlspecialchars() or whatever is needed in your situation.)
Give each input its own name or use:
<input type="text" name="location[]" id="location1" />
Then PHP will treat it like an array.
Either give each input a different name attribute, for example location1, location2, location3 and location4 then access with $_POST['location1'] $_POST['location2'] etc.
Alternatively (and probably preferred if this form is being generated 'dynamically'), change the name attribute for each input to location[] then access the values entered as an array in PHP. For example...
HTML
<form method="post">
<input type="text" name="location[]" id="location1" />
<input type="submit" value="Submit!" />
<input type="text" name="location[]" id="location2" />
<input type="submit" value="Submit!" />
<input type="text" name="location[]" id="location3" />
<input type="submit" value="Submit!" />
<input type="text" name="location[]" id="location4" />
<input type="submit" value="Submit!" />
</form>
PHP
print_r($_POST['location']);
echo "<form method='post'>";
for($x=1;$x<=4;$x++)
{
echo "<input type='text' name='location".$x."' id='location".$x."'/>";
echo "<input type='submit' value='Submit!' />";
}
echo "</form>";

Categories