0

I am trying to print a label and a textbox together in a HTML file that I am trying to write using fopen, fputs in PHP. For some reason the output is just a text box and not the label along with the textbox. This is the piece of code I am using.?
I have also tried for line 4 $var4.$var5 and "$var4"."$var5" with no success.

if($ele == 'txtbox')
{
$var5 = "<input type = 'text' name = 'lbl1'><br><br>";
$element2 = "$var4$var5";
echo $element2;

}

Edited by raghujosh: n/a

6
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by ko ko
0

I really don't understand your piece of code that much, and what is to be added to labels and text boxes
here is something that might help

if($ele == 'txtbox')
{
$var5 = "<label for=\"lbl1\">$somevalue</label>";
$var5 .= "<input type=\"text\" name=\"xyz\" id=\"lbl1\">$anothervalue</input>";
}
echo $var5;

if its not clear for you, please give me more information regarding your objective and I'll be glad to help

0

like saadsaidi said, we need more information. are you getting an error? Has the code met the condition if($ele == 'txtbox') to display the textbox?

0

I really don't understand your piece of code that much, and what is to be added to labels and text boxes
here is something that might help

if($ele == 'txtbox')
{
$var5 = "<label for=\"lbl1\">$somevalue</label>";
$var5 .= "<input type=\"text\" name=\"xyz\" id=\"lbl1\">$anothervalue</input>";
}
echo $var5;

if its not clear for you, please give me more information regarding your objective and I'll be glad to help

Thanks very much. Your code kind of helped, but not with my objectives. I will explain my program. I am creating a HTML form builder. That is a user can select from a dropdown, HTML elements(such as List box, Textbox, Radio button, Checkbox). They can also enter a label for each. There are 5 dropdowns available. The php form to which I post data, will take the label name and the dropdown value name. Then it will write the label and the HTML element to an HTML file on the server(it creates a new file). When I try to do it for only 1 value, I get the desired HTML file with the label and the HTML element. But If I try to put it in a loop 5 times and then try to write it, it wont work. I am mentioning all the code of this application.

1. CODE OF THE MAIN PAGE

<html>
<head>
Welcome, Lets create AppName
</head>
<body>


<form action = "write4.php" method = "post">

<div style " 
	margin-top:25px;
	margin-left:50px;
	margin-right:50px;
	margin-bottom:25px;
">

<div style = "width:500px;height:800px;border:2px solid blue;
	padding-top:75px;
	padding-left:100px;
	padding-right:100px;
	padding-bottom:5px;
">


Please enter a name for the App <input type = "text" name = "name">

<table border = "1"><tr><th>Choose the Label</th><th>Choose the element</th></tr>

<tr><td><input type = "text" name = "label1" /></td> <td> <select name = "elementtype1">
						    <option value = ''>      </option>
  						    <option value='txtbox'>Text Box</option>
  						    <option value='lstbox'>List Box</option>
						    <option value='chkbox'>Check Box</option>
  						    <option value='radio'>Radio Button</option>
						    </select></td></tr>

<tr><td><input type = "text" name = "label2" /></td> <td> <select name = "elementtype2">
						    <option value = ''>      </option>
  						    <option value='txtbox'>Text Box</option>
  						    <option value='lstbox'>List Box</option>
						    <option value='chkbox'>Check Box</option>
  						    <option value='radio'>Radio Button</option>
						    </select></td></tr>

<tr><td><input type = "text" name = "label3" /></td> <td> <select name = "elementtype3">
						    <option value = ''>      </option>
  						    <option value='txtbox'>Text Box</option>
  						    <option value='lstbox'>List Box</option>
						    <option value='chkbox'>Check Box</option>
  						    <option value='radio'>Radio Button</option>
						    </select></td></tr>

<tr><td><input type = "text" name = "label4" /></td> <td> <select name = "elementtype4">
						    <option value = ''>      </option>
  						    <option value='txtbox'>Text Box</option>
  						    <option value='lstbox'>List Box</option>
						    <option value='chkbox'>Check Box</option>
  						    <option value='radio'>Radio Button</option>
						    </select></td></tr>

<tr><td><input type = "text" name = "label5" /></td> <td> <select name = "elementtype5">
						    <option value = ''>      </option>
  						    <option value='txtbox'>Text Box</option>
  						    <option value='lstbox'>List Box</option>
						    <option value='chkbox'>Check Box</option>
  						    <option value='radio'>Radio Button</option>
						    </select></td></tr>

</table>

<input type = "submit" value = "Submit">
</form>
</div>
</body>

</html>

2. CODE THAT WORKS(without loop)

<?php

#grab name from previous form

$name = $_POST['name'];


$i = 1;
$var4= $_POST['label'.$i];
echo "$var4<br>";

$ele1 = $_POST['elementtype1'];

if($ele1 == 'txtbox')
{
$var5 = "$var4";
$var5 .= "<input type=\"text\" name=\"xyz\">";
echo $var5;   
}
else if ($ele1 == 'lstbox')
{

$var5 = $var4."<select>
				<option value = ''>      </option>
  						    <option value='LI1'>List Item1</option>
  						    <option value='LI2'>List Item 2</option>
						    <option value='LI3'>List Item 3</option>
  						    <option value='LI4'>List Item 4</option>
						    </select><br><br>";
}
else if ($ele1 == 'chkbox')
{

$var5 = $var4."<input type = 'checkbox' name = 'lbl1'><br><br>";
}

else if ($ele1 == 'radio')
{

$var5 = $var4."<input type = 'radio' name = 'lbl1'><br><br>";
}
else
{
redirect("http://login/AppCreator.html");
}

#set up HTML template data

$HTML = "<html><head><title>$name</title></head><body><h1>Hello $name </h1><p>Nice to meet you!</p> $var5 </body></html>";

$PATH = $_SERVER['DOCUMENT_ROOT']; #get server path

$save_path=$PATH.'/applications/Raghu/login/'; #define target path

$temp='file.txt'; #define temporary target name

$dest="$name.html"; #define final destination target name, dynamically generated by user's name

$fp = fopen($save_path.'/'.$temp, "w", 0); #open for writing

fputs($fp, $HTML); #write all of template data to our opened file

fclose($fp); #close the file

#rename tmp file to dest file

rename($save_path.'/'.$temp,$save_path.'/'.$dest); 
?>

3.CODE THAT DOES NOT WORK(WITH loop)

<?php

#grab name from previous form

$name = $_POST['name'];


for($i=0;$i<=5; $i++)
{
$elementlabel.$i = $_POST['label.$i'];
$ele.$i = $_POST['elementtype.$i'];
if($ele.$i == 'txtbox')
{
$elementa = $elementlabel.$i;

$element.$i = $elementa."<input type = 'text' name = 'lbl1'><br><br>";
}
else if ($ele.$i == 'lstbox')
{
$elementa = $elementlabel.$i;

$element.$i = $elementa."<select>
				<option value = ''>      </option>
  						    <option value='LI1'>List Item1</option>
  						    <option value='LI2'>List Item 2</option>
						    <option value='LI3'>List Item 3</option>
  						    <option value='LI4'>List Item 4</option>
						    </select><br><br>";
}
else if ($ele.$i == 'chkbox')
{
$elementa = $elementlabel.$i;

$element.$i = $elementa."<input type = 'checkbox' name = 'lbl1'><br><br>";
}

else if ($ele.$i == 'radio')
{
$elementa = $elementlabel.$i;

$element.$i = $elementa."<input type = 'radio' name = 'lbl1'><br><br>";
}
else
{
header("Location:http://resolv.org.s110820.gridserver.com/applications/Raghu/login/AppCreator.html");
}
}



#set up HTML template data

$HTML = "<html><head><title>$name</title></head><body><h1>Hello $name</h1><p>Nice to meet you!</p>$element1  $element2 $element3  $element4 $element5  </body></html>";

$PATH = $_SERVER['DOCUMENT_ROOT']; #get server path

$save_path=$PATH.'/applications/Raghu/login'; #define target path

$temp='file.txt'; #define temporary target name

$dest="$name.html"; #define final destination target name, dynamically generated by user's name



$fp = fopen($save_path.'/'.$temp, "w", 0); #open for writing

fputs($fp, $HTML); #write all of template data to our opened file

fclose($fp); #close the file

#rename tmp file to dest file

rename($save_path.'/'.$temp,$save_path.'/'.$dest); 
?>
0

i hope this code will be helpful to u....

<?php
$i="abc";
?>
<form action="" method="POST">
<input type="text" name="abc">
<input type="submit" value="submit">
</form>
<?php
if(isset($_POST['abc']))
echo $i.$_POST['abc'];
?>

if not clear specify what u need...

0
$var4 = "<input type = 'text' name = 'lbl1'>";
$var5 = "<input type = 'text' name = 'lbl2'>";
$element2 = $var4.'<br><br>'.$var5;
echo $element2;
0

i hope this code will be helpful to u....

<?php
$i="abc";
?>
<form action="" method="POST">
<input type="text" name="abc">
<input type="submit" value="submit">
</form>
<?php
if(isset($_POST['abc']))
echo $i.$_POST['abc'];
?>

if not clear specify what u need...

Thanks, I have explained my program completely. Can you please reply to tht. Its the previous post to yours.

0

base on my experience i did it this way

youre original code
for($i=0;$i<=5; $i++)
{
$elementlabel.$i = $_POST['label.$i'];
$ele.$i = $_POST['elementtype.$i'];
}
//here's mine
for($i=0;$i<=5; $i++)
{
$label = 'label'.$i;
$elementtype = 'elementtype'.$i;

$elementlabel.$i = $_POST[$label];
$ele.$i = $_POST[$elementtype];
}
0

Concatenation needs period '.'. You need to place the period between the string or variable that you want to concate.

$string1 = "This is string 1";
$string2 = "This is string 2";
$string 1 . $string2;
----------------------------------
$string1 . ". " . $string2;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.