I have been trying to display this drop down list in my PHP form but when I open it on the browser it gives me a blank page, I have tried opening the page by removing the list and it runs properly. I also tried running the drop down list code independently and it runs properly. I have checked the and codes too but to no avail. The form is in a function as shown below:
function showForm() {
include("library/daloradius.conf.php");
echo " <b>
".$configValues['CONFIG_SIGNUP_MSG_TITLE']."
</b>
<br/><br/>
<form name='signup' action='".$_SERVER['PHP_SELF']."' method='post'>
<table>
<tr><td><b>First name:</b></td><td> <input type='text' value='Conference' name='firstname' /> </td></tr>
<tr><td><b>Number:</b></td><td> <input type='text' value='' name='number' /> </td></tr>
<tr><td><b>Bundle Type</b></td><td>
<select name = "Bundle" size = "1"> <option value ="10MB">10MB</option><option value ="25MB">25MB</option><option value ="50MB">50MB</option></select></td></tr>
<tr><td><b>Enter the verification code in the image:</b> <img src='include/common/php-captcha.php'></td>
<td><input name='formKey' type='text' id='formKey' /></td></tr>
</table>
<br/><br/>
<tr><td><input type='submit' name='submit' value='Register' /> </td></tr>
<br/><br/>
</form>
";
}
switch ($status) {
case "firstload":
You are jumbling with single and double quotes.
<select name = "Bundle" size = "1"> <option value ="10MB">10MB</option><option value ="25MB">25MB</option><option value ="50MB">50MB</option></select></td></tr>
Change it to:
<select name = 'Bundle' size = '1'> <option value ='10MB'>10MB</option><option value ='25MB'>25MB</option><option value ='50MB'>50MB</option></select></td></tr>
Please check for whole code the same way.
Related
Please I need assistance on how to get the input values of field that was generated by a loop:
if($moreDetails){
while($row=mysqli_fetch_assoc($moreDetails)){
$id="$row[id]";
$sname="$row[sname]";
$fname="$row[fname]";
$sub="$row[$subject]";
echo "
<tr>
<td>$id</td>
<td>$sname</td>
<td>$fname</td>
<td><label for='score'></label>
<input type='text' class='form-control' name='score'/>
<input type='hidden' name='assessment'/>
</td>
</tr>
";
}
}
My challenge is to get the input of the score entries.
You should give the inputs array-style names.
if($moreDetails){
while($row=mysqli_fetch_assoc($moreDetails)){
$id="$row[id]";
$sname="$row[sname]";
$fname="$row[fname]";
$sub="$row[$subject]";
echo "
<tr>
<td>$id</td>
<td>$sname</td>
<td>$fname</td>
<td><label for='score'></label>
<input type='text' class='form-control' name='score[$id]'/>
<input type='hidden' name='assessment[$id]'/>
</td>
</tr>
";
}
}
Then when you're processing the form, the $_POST parameters will be arrays, so you can access $_POST['score'][$id] and $_POST['assessment'][$id].
It's also strange that you don't have value="something" in the hidden input. Are you using Javascript on the client side to fill this field in automatically?
I need assistance in taking the next step in inserting data entered into a dynamically-generated form. I have looked for a number of days at other similar questions and am still missing a piece.
Here is my HTML form (minus error trapping/validations):
<form id="form" name="form" method="post" action="recipeaddsubmit.php">
<table id="myTable">
<tr>
<td width="10%">Amount</td>
<td width="10%">Measure</td>
<td width="35%">Ingredient</td>
</tr>
<tr>
<td valign="top">
<input type="text" name="Amt1" id="Amt1" size="1" />
<input type="text" name="Amt2" id="Amt2" size="1" />
</td>
<td valign="top">
<select name="Measure" id="Measure">
<option>Cup</option>
<option>Ounce</option>
</select>
</td>
<td valign="top">
<input type="text" name="Ing" id="Ing" size="40" />
</td>
</tr>
</table>
<button type="button" onclick="displayResult()">Insert new row</button>
<input type="submit" name="button" id="button" value="Submit" />
</form>
Here is the javascript in my header:
<script>
function displayResult()
{
var table=document.getElementById("myTable");
var row=table.insertRow(-1);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
var cell3=row.insertCell(2);
cell1.innerHTML="<input type='text' name='Amt1' id='Amt1' size='1' />
<input type='text' name='Amt2' id='Amt2' size='1' />";
cell2.innerHTML="<select name='Measure' id='Measure'> <option>Cup</option>
<option>Ounce</option></select>";
cell3.innerHTML="<input type='text' name='Ing' id='Ing' size='40' />";
}
</script>
And here is my attempted/partial mysqli insert statement (checkInput is a self-created validation function I have used before without issue):
$amt1 = checkInput($_POST['Amt1']);
$amt2 = checkInput($_POST['Amt2']);
$measure = checkInput($_POST['Measure']);
$ing = checkInput($_POST['Ing']);
$ingAddQuery ="INSERT INTO Ingredient (Amt1, Amt2, Measure, Ing)
VALUES ({$amt1}, {$amt2}, {$measure}, {$ing})";
mysqli_query($mysqli,$ingAddQuery);
if (!mysqli_query($mysqli,$ingAddQuery))
{
die('Error: ' . mysqli_error());
}
What I don't understand is how to incorporate a foreach loop in terms of how to increment for a certain number of rows; I understand the concept but not the application in this case.
Thank you for your assistance!
change the name from amt1 to amt1[] and etcetera...
so
<input type="text" name="Amt1[]" id="Amt1[]" size="1" />
When you submit the form,
$_POST['Amt1']; //is an array
will be an array, so you could do
$Amt1Array = $_POST['Amt1'];
foreach($Amt1Array => $Amt1){
//do stuff here
}
Better yet you can index the array using the js to create names like...
<input type="text" name="Amt1[0]" id="Amt1[0]" size="1" />
<input type="text" name="Amt2[0]" id="Amt2[0]" size="1" />
<input type="text" name="Amt1[1]" id="Amt1[1]" size="1" />
<input type="text" name="Amt2[1]" id="Amt2[1]" size="1" />
Then in the PHP you could
$Amt1Array = $_POST['Amt1'];
$Amt2Array = $_POST['Amt2'];
foreach($Amt1Array as $key => $Amt1Value){
$Amt2Value = $Amt2Array[$key];
//do stuff with rows
}
I have a suggestion.
Why don't u create a hidden input type.
<input type="hidden" name="cellCount" value="0" />
Each time u insert a new row, change value of this hidden field. This will not show on browser. This hidden element will also get submit when u submit form. this can be retrieved on server by $_POST["cellCount"].
Hope this will help u.
I have a little problem with my code and I don't know what is wrong in my code... So I have a two form where the first load is the "view.php" then the second is "checkbox_building.php".. My problem is when I removed the button of delete in "view.php" the dropdown list can proceed to "checkbox_building.php". but when I placed it back, its not working (its not proceeding to "checkbox_building.php") I'm kinda confuse about this.
Here's my code for "view.php"
<fieldset width= "200px">
<form name='form' method='post' action=''>
Select Network: <select name="netName" onChange="this.form.action='checkbox_building.php'; this.form.submit()">
<option value="" >- Select -</option>
<?php
include 'connect.php';
$q = mysql_query("select fldNetname from tblnetwork");
while ($row1 = mysql_fetch_array($q))
{
echo "<option value='".$row1[fldNetname]."'>".$row1[fldNetname]."</option>";
$net = $row1[fldNetname];
}
?>
</select>
<input type='submit' name='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
</form>
</fieldset>
thanks.!
just as a guess, just from your code:
correct the flaw, then
change
<input type='submit' name='submit'
to
<input type='button' name='dosubmit'
and
<form name='form' method='post' action=''>
to
<form name='<someUsefullName>' method='post' action=''>
and all references to this as well, since "form" is a reserved word in IE and this.form.action may lead to errors there.
just remove name='submit' and try
<input type='submit' name='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
so it will be
<input type='submit' value='Delete Building/s' onClick="this.form.action='delete_building.php'; this.form.submit()">
its because this.form.submit is default submit function, but in your code its an input element :)
I have a php page that displays all of the service logs for a given site in a table.
At the end of the table I have a new row that has an "Add new service log" button.
Clicking the button hides that row and displays a new row with a form and the desired inputs as well as a new row with buttons "Save" and "Cancel".
The "Save" button calls a Javascript function that checks that the key input has been filled out. When hitting "Save", I see in the console log
TypeError: this.form is null
Here is my code:
// SQL Query
// Table data of queried results
// Add a new service log
echo "<tr id='AddNew'>
<td><input type=button value='Add New' onclick=\"$('#AddNew').hide();$('#AddNewHid').show();$('#SaveCancel').show();\"></td>
<td colspan=12>   </td></tr>
<form name='AddNewLog' method='POST' action='servicelook.php' id='AddNewService'>
<tr style='display: none;' id='AddNewHid'>
<td><input type='text' value='$lastID' name='ticketid' size=10></td>
<td><input type='text' value='$siteID' name='SiteID' size=4></td>
<td><input type='text' value='$siteName' name='SiteName' size=20></td>
<td><input type='text' value='$userid' name='takenBy' size=4></td>
<td><input type='text' value='$now' name='callTime' size=20></td>
<td><input type='text' value='' name='caller' size=20></td>
<td><input type='text' value='' name='callPhone' size=14></td>
<td><textarea name='issue' value = '' rows=3 cols=10></textarea></td>
<td><textarea name='fix' value = '' rows=3 cols=10></textarea></td>
<td><input type='text' value='$userid' name='solvedBy' size=4></td>
<td><input type='text' value='$now' name='solvedTime' size=20></td>
<td style='min-width:100px;max-width:100px;'><input type='checkbox' name='fup' value='fup'>Follow Up</td></tr>
<input type='hidden' value='Yes' name='AddNew'>
<input type='hidden' value='$userid' name='userid'>
<input type='hidden' value='$session' name='session'>
<input type='hidden' value='$siteid' name='siteid'>
<tr style='display: none;' id='SaveCancel'>
<td colspan=2>
<input name='save' type='button' onclick='inputCheck(this.form.issue);' value='Save'>  
<input type='button' value='Cancel' onclick=\"$('#AddNew').show();$('#AddNewHid').hide();$('#SaveCancel').hide();\"></td>
<td colspan=11>   </td>
</tr></form>";
echo "</table>";
My inputCheck function looks like this:
<script type="text/javascript">
function inputCheck(areaName)
{
console.log("checking...");
if (areaName.value.length > 0)
{
$('form#AddNewService').submit();
}
else
{
alert("You didn't describe the problem!");
}
} // end noteCheck function
</script>
I tried changing the submit button to this:
<input type=submit value=Save>
but nothing happens, nothing on the page or in the log.
Anyone have any idea as to what I am doing wrong or what the problem is here?
Thanks in advance!
EDIT:
After using Steven's advice, I was able to successfully submit the form.
However, the inputs aren't properly being sent. I am submitting to the same page so that the table reloads and and the user can see their latest entry. At the beginning of the script I have this:
if($AddNew == 'Yes')
{
echo "YES...Adding New";
echo $ticketid .$SiteID. $SiteName. $takenBy. $callTime. $caller. $callPhone. $issue. $fix. $solvedBy. $solvedTime;
// Start SQL Query
}
The inputs return null. Is there something wrong with the way I am setting my inputs?
The general strategy here is to make the save button a submit button, then put the validation on the form's submit handler and cancel submit if validation fails, e.g.
<form onsubmit="return inputCheck(this.issue);" ...>
then if validation fails, return false from the inputCheck function.
Your issue is probably because you have a form in a place it can't be, so it's being moved outside the table, i.e. you have:
<table>
<form>
...
</form>
</table>
which the browser is "correcting" to:
<table>
...
</table>
<form>
</form>
Now the form is outside the table but the controls are still inside it. So change the markup to:
<form>
<table>
...
</table>
</form>
so the table and form controls stay inside the form.
when this.form is null:
onclick='inputCheck(this.form.issue);'
replace with:
onclick='inputCheck();'
and edit your inputCheck method:
function inputCheck() {
console.log("checking...");
if ($('textarea[name=issue]').val().length > 0){
$('form#AddNewService').submit();
} else {
alert("You didn't describe the problem!");
}
}
I have a the following php file. displayitems.php
<?php
*
*
*
echo "<form action='http://retailthree.nn4m.co.uk/alex/add_data.html'>";
echo "<input type='hidden' name='value' value='$value'/>";
echo "<button type='submit'>Add</button>";
echo "</form>";
?>
Then the html file. add_data.html:
<form method="post" name="form">
<table id="mytable" border="1">
<tr>
<td>Trend <input type="text" name="trend" size="20"></td>
//many other fields
</tr>
</table>
</forn>
Then the aforementioned html will perform an action on a php file.
However that I want to achieve is to pass the hidden data ->$value from the first php file, to the Trend input box(to print the $value content to the input box). Is this possible?
You would simple use the posted variable and place it in the value attribute of your <input> like so:
<input type="text" value="<?php echo $_GET['value'] ?>" name="trend" size="20">
Of course you should do some validation before echoing it to the <input>
EDIT:
Quite rightly mentioned by #ocanal - GET is the default method for forms. You will not be able to process these forms with PHP if your file is *.html it must be a *.php file.
change the name of add_data.html file to add_data.php use following code in add_data.php file
<?php
// your php code
?>
<form method="post" name="form">
<table id="mytable" border="1">
<tr>
<td>
Trend <input type="text" name="trend" size="20"
value="<?php echo $_POST['trend'] ?>">
</td>
//many other fields
</tr>
</table>
</forn>
I'm a little lost but assuming you mean that you want the hidden value to appear in a text input field on another page I would suggest this:
HTML page
<form name='form' action='yourPhpFile.php' method='POST'>
<input name='hiddenGuy' type='hidden' value='hello from the hidden guy'/>
<input type='submit' value='Send'/>
</from>
Now for your php file called yourPhpFile.php
<?php
//your value from the hidden field will be held in the array $_POST from the previous document.
//the key depends on your field's name.
$val = $_POST['hiddenGuy'];
echo "<form name='form' action='yourPhpFile.php' method='POST'>
<input name='showingInText' type='text' value='".$val."'/>
</from>";
?>
This can be achieved on the same page too by removing the form action attribute. and echoing the a different input type and value depending on whether $_POST is set using the isset method.
if(isset($_POST['hiddenGuy'])){
echo "<input name='showingInText' type='text' value='".$_POST['hiddenGuy']."'/>";
}
else{
echo "<input name='hiddenGuy' type='hidden' value='hello from the hidden guy'/>
<input type='submit' value='Send'/>";
}