First my code:
<?php
echo 'Hello
<FORM ACTION="uebung3.php" METHOD="post">
<P>
<LABEL FOR="vorname">Vorname: </LABEL>
<INPUT TYPE="text" NAME="vorname">
<LABEL FOR="nachname">Nachname: </LABEL>
<INPUT TYPE="textarea" NAME="nachname">
<LABEL FOR="email">E-Mail: </LABEL>
<INPUT TYPE="text" NAME="email">
<INPUT TYPE="radio" NAME="geschlecht" VALUE="Maskulin"> Maskulin
<INPUT TYPE="checkbox" NAME="geschlecht" VALUE="Feminin"> Feminin
<input type="password" for="pw" NAME="PW">
<INPUT TYPE="submit" VALUE="Absenden">
<INPUT TYPE="reset" VALUE="Zurücksetzen">
</P>
</FORM>
';
?>
So if i run that on my xampp-Server, it shows a "Hello" and the Form in a new line.
What must I do that all this is written in one line?
Thanks
You need to remove the <p> element and display the form inline.
<?php
echo 'Hello
<FORM ACTION="uebung3.php" METHOD="post" style="display:inline">
<LABEL FOR="vorname">Vorname: </LABEL>
<INPUT TYPE="text" NAME="vorname">
<LABEL FOR="nachname">Nachname: </LABEL>
<INPUT TYPE="textarea" NAME="nachname">
<LABEL FOR="email">E-Mail: </LABEL>
<INPUT TYPE="text" NAME="email">
<INPUT TYPE="radio" NAME="geschlecht" VALUE="Maskulin"> Maskulin
<INPUT TYPE="checkbox" NAME="geschlecht" VALUE="Feminin"> Feminin
<input type="password" for="pw" NAME="PW">
<INPUT TYPE="submit" VALUE="Absenden">
<INPUT TYPE="reset" VALUE="Zurücksetzen">
</FORM>
';
?>
Remove the paragraph break '<P>'
You should really use a heredoc for this type of HTML output in PHP. Technically, the <p> tag should be around the Hello, not the form. You're looking for something like:
<?php
echo <<<EOT
Hello
<FORM ACTION="uebung3.php" METHOD="post">
<LABEL FOR="vorname">Vorname: </LABEL>
<INPUT TYPE="text" NAME="vorname">
<LABEL FOR="nachname">Nachname: </LABEL>
<INPUT TYPE="textarea" NAME="nachname">
<LABEL FOR="email">E-Mail: </LABEL>
<INPUT TYPE="text" NAME="email">
<INPUT TYPE="radio" NAME="geschlecht" VALUE="Maskulin"> Maskulin
<INPUT TYPE="checkbox" NAME="geschlecht" VALUE="Feminin"> Feminin
<input type="password" for="pw" NAME="PW">
<INPUT TYPE="submit" VALUE="Absenden">
<INPUT TYPE="reset" VALUE="Zurücksetzen">
</FORM>
EOT;
?>
Even by removing <p> tags, your hello will still appear on a seperate line. This is because it is outside your <form> tag.
Put it inside <form> like this, while removing the <p> tags:
<?php
echo '<FORM ACTION="uebung3.php" METHOD="post">Hello
<LABEL FOR="vorname">Vorname: </LABEL>
<INPUT TYPE="text" NAME="vorname">
<LABEL FOR="nachname">Nachname: </LABEL>
<INPUT TYPE="textarea" NAME="nachname">
<LABEL FOR="email">E-Mail: </LABEL>
<INPUT TYPE="text" NAME="email">
<INPUT TYPE="radio" NAME="geschlecht" VALUE="Maskulin"> Maskulin
<INPUT TYPE="checkbox" NAME="geschlecht" VALUE="Feminin"> Feminin
<input type="password" for="pw" NAME="PW">
<INPUT TYPE="submit" VALUE="Absenden">
<INPUT TYPE="reset" VALUE="Zurücksetzen">
</FORM>
';
?>
Related
guys I have a problem with a PHP page.
I'm trying to make a form to update the record of a DB.
I'm displaying the form with an echo but I have some problems with quotes
<? echo'
<img src="logo.jpg">
<fieldset>
<input name="aspettogen2" type="text" value="<?php echo $aspettogen;?>">
</fieldset>
<fieldset>
<input name="desc" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="ragsoc" type="text" maxlength="100">
</fieldset>
<fieldset>
<input name="numcivico" type="text" maxlength="20">
</fieldset>
<fieldset>
<input name="validita" type="text">
</fieldset>
<fieldset>
<input name="odierna" type="data">
</fieldset>
<fieldset>
<input name="preavviso" type="text">
</fieldset>
<fieldset>
<input name="scadenza" type="text">
</fieldset>
<fieldset>
<input name="presc" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="freq" type="number">
</fieldset>
<fieldset>
<input name="datacontr" type="text">
</fieldset>
<fieldset>
<input name="proxcontr" type="text">
</fieldset>
<fieldset>
<input name="note" type="text">
</fieldset>
</form>
</div>
</body>
</html>';
in the first fieldset value="<?php echo $aspettogen;?"> it appears gray because the quote after the echo turn it into a "comment" and i cant print the value..
how can i solve it?
i've tried to do like this Value="'<?php echo $aspettogen;?'"> but i receive the error Parse error: syntax error, unexpected '?' in /var/..... on line 50
You have wrong syntax in that line. I have made the necessary changes.
Code:
<? echo'
<img src="logo.jpg">
<fieldset>
<input name="aspettogen2" placeholder="Aspetto Generale" type="text" value="<?php echo $aspettogen;?>">
</fieldset>
<fieldset>
<input name="desc" placeholder="Descrizione" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="ragsoc" placeholder="Ragione Sociale" type="text" maxlength="100">
</fieldset>
<fieldset>
<input name="numcivico" placeholder="Numero Civico" type="text" maxlength="20">
</fieldset>
<fieldset>
<input name="validita" placeholder="Validita" type="text">
</fieldset>
<fieldset>
<input name="odierna" placeholder="Data" type="data" id="today" readonly >
</fieldset>
<fieldset>
<input name="preavviso" placeholder="Preavviso" type="text">
</fieldset>
<fieldset>
<input name="scadenza" placeholder="Scadenza" type="text">
</fieldset>
<fieldset>
<input name="presc" placeholder="Prescrizioni" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="freq" placeholder="Frequenza (in giorni)" type="number">
</fieldset>
<fieldset>
<input name="note" placeholder="Note" type="text">
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit">Inserisci</button>
</fieldset>
</form>
</div>
</body>
</html>';?>
I've been asking a lot of questions as of late related to creating RESTful services with PHP. My question is this:
Can all services (GET, POST, PUT, DELETE) be done from a single web form using radio buttons?
This is what I am picturing in my head:
<form action="MyService.php" method="GET">
<label for="username">Username</label>
<input type="text" name="username" id="username" /><br />
<label for="password">Password</label>
<input type="password" name="password" id="password" /><br />
<label for="id">Task ID</label>
<input type="text" name="id" id="id"/><br />
<label for="desc">Task Description</label>
<input type="text" name="desc" id="desc"/><br />
<label>
<input type="radio" name="service" value="getRadio" checked/> GET
</label>
<label>
<input type="radio" name="service" value="postRadio" /> POST<br />
</label>
<input type="hidden" name="REQUEST_METHOD" value="GET"/><br />
<input type="hidden" name="REQUEST_METHOD" value="POST"/><br />
<input type="hidden" name="REQUEST_METHOD" value="PUT"/><br />
<input type="hidden" name="REQUEST_METHOD" value="DELETE"/><br />
<input type="submit" name="submit" value="ACTION"/>
</form>
It's incomplete so far, but what I'm thinking of trying to do is have radio button selections for each service, then outline my php file like this:
$request = $_SERVER["REQUEST_METHOD"]
switch($request) {
case 'GET':
// logic for GET based on radio button selected
break;
case 'POST':
// logic for POST based on radio button selected
break;
// and then PUT and DELETE
}
Is this doable? If so, am I on the right track, or do I need to make changes?
if you want to use the forms, and providing it does work as seems by this spec, then you can use some javascript to change the method of your form onsubmit.
<form action="MyService.php" method="GET" onsubmit='this.method = this.service.value'>
<label for="username">Username</label>
<input type="text" name="username" id="username" /><br />
<label for="password">Password</label>
<input type="password" name="password" id="password" /><br />
<label for="id">Task ID</label>
<input type="text" name="id" id="id"/><br />
<label for="desc">Task Description</label>
<input type="text" name="desc" id="desc"/><br />
<label>
<input type="radio" name="service" value="GET" checked/> GET
</label>
<label>
<input type="radio" name="service" value="POST" /> POST<br />
</label>
<label>
<input type="radio" name="service" value="PUT" /> PUT
</label>
<label>
<input type="radio" name="service" value="DELETE" /> DELETE<br />
</label>
<input type="hidden" name="REQUEST_METHOD" value="GET"/><br />
<input type="hidden" name="REQUEST_METHOD" value="POST"/><br />
<input type="hidden" name="REQUEST_METHOD" value="PUT"/><br />
<input type="hidden" name="REQUEST_METHOD" value="DELETE"/><br />
<input type="submit" name="submit" value="ACTION"/>
</form>
I have this form designed and have no idea how to hook it up with php to send the data by email. The upload file must be jpeg and size no more than 30kb. Can you help me please?
For newbee like me it is big challenge. Yet, its a piece of cake for pros like you.
<!doctype html>
<html lang="en">
<head>
<title>application form</title>
</head>
<body>
<form method="post" action="submit.php">
<input type="text" name="fstname" placeholder="First Name"><br>
<input type="text" name="lstname" placeholder="Last Name"><br>
<input type="text" name="faname" placeholder="Father's Name"><br>
<input type="text" name="maname" placeholder="Mother's Name"><br>
<input type="tel" name="mobile" placeholder="Mobile No."><br>
<input type="tel" name="phone" placeholder="Phone No."><br>
<input type="email" name="email" placeholder="Email ID"><br>
<input type="text" name="adrs" placeholder="Pemanent Address" maxlength="250"><br>
<input type="text" name="cnt" placeholder="Country"><br>
<input type="text" name="pin" placeholder="Pin Code"><br>
<input type="text" name="adrs2" placeholder="Present Address" maxlength="250"><br>
<input type="text" name="cnty" placeholder="Country"><br>
<input type="text" name="zip" placeholder="Pin Code"><br>
<fieldset>
<legend>What is Your Gender?</legend>
<input type="radio" name="gen" value="male" checked />Male
<input type="radio" name="gen" value="female" />Female
<input type="radio" name="gen" value="other" />Other
</fieldset>
<fieldset>
<legend>What is Your Religon</legend>
<input type="radio" name="rel" value="hindu" checked />Hindu
<input type="radio" name="rel" value="muslim" />Muslim
<input type="radio" name="rel" value="christian" />Christian
<input type="radio" name="rel" value="other" />Other
</fieldset>
<fieldset>
<legend>Are you physically challenged?</legend>
<input type="radio" name="cha" value="no" checked />No
<input type="radio" name="cha" value="yes" />Yes
</fieldset>
<fieldset>
<legend>Choose the Training Method.</legend>
<input type="radio" name="tm" value="ait" checked />AIT
<input type="radio" name="tm" value="its" />ITS
<input type="radio" name="tm" value="mes" />MES
<input type="radio" name="tm" value="aajee" />AAJEEVIKA
<input type="radio" name="tm" value="sch" />SCHEME
<input type="radio" name="tm" value="dass" />DIRECT ASSESSING
<input type="radio" name="tm" value="ot" />OTHER
</fieldset><br>
<input type="text" name="cmt" placeholder="Community"><br>
<input type="text" name="edu" placeholder="Education"><br>
<input type="text" name="oq" placeholder="Other Qualifications"><br>
<span>Following files be attached in jpeg format, size no more than 30kb</span><br>
<input type="file" value="sign"> Signature File.<br>
<input type="file" value="tc"> TC Copy.<br>
<input type="file" value="ms1"> Marksheet Copy 1.<br>
<input type="file" value="ms2"> Marksheet Copy 2.<br>
<input type="file" value="oq1"> Other Qualification Copy 1.<br>
<input type="file" value="oq2"> Other Qualification Copy 2.<br>
<input type="file" value="cc"> Community Certificate Copy.<br>
<input type="file" value="adrsp"> Address Proof Copy.<br>
<input type="file" value="adar"> Adhar Card Copy.<br>
<input type="reset"> <input type="submit" value="Submit">
</form>
</body>
</html>
Here it goes :
Make your HTML as :
<input name="upload[]" type="file" multiple="multiple" />
and in your php code
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
Hope this helps.
I am trying to echo a form when a function is called. My code is as follow :
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories().'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}
but wp_dropdown_categories() is displayed twice. Here is the HTML output:
<div class="entry-content">
<!-- this should not be displayed -->
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<!-- form starts here -->
<form action="" method="post">
<input type="text" id="input-title" size="45" name="post_title">
<textarea id="text-desc" cols="66" name="post_content" rows="5"></textarea>
<select class="postform" id="cat" name="cat">
<option value="9" class="level-0">Entertainment</option>
</select>
<input type="hidden" value="1" name="new_post">
<input type="submit" value="Post" name="submit" class="subput round">
</form>
</div>
any idea why wp_dropdown_categories() is called twice?
By default, wp_dropdown_categories() echos the result. So you should either break your code in the following way:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>
';
wp_dropdown_categories();
echo '<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
or pass the echo variable to the function as zero as such:
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories('echo=0')).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
Try this...
See the documentation for this function wp_dropdown_categories()
function add_post(){
....
echo '<form method="post" action="">
<input type="text" name="post_title" size="45" id="input-title"/>
<textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea>'
.wp_dropdown_categories(array('echo'=>0)).'
<input type="hidden" name="new_post" value="1"/>
<input class="subput round" type="submit" name="submit" value="Post"/>
</form>
';
}
I have been using php to try and email the user entered content from a web form to an email address. Been messing around with the php code to no avail. Here's the web form:
<form action="form2email.php" method="post">
<div id="problem" class="fluid">
<textarea name="problem" cols="50" rows="4" placeholder="enter problem here" row="4"></textarea>
</div>
<div id="email" class="fluid">
<input type="email" name="email" placeholder="email optional">
</div>
<div id="userOptions" class="fluid">
<label for="yes">Yes</label>
<input name="publish" type="radio" value="Yes">
<label for="no">No</label>
<input type="radio" name="publish" value="No">
<label for="responder"><b>Michael</b></label>
<input name="responder" type="checkbox" value="Michael" id="responder">
<label for="responder"><b>Jennifer</b></label>
<input type="checkbox" name="responder" value="Jennifer" id="responder">
<label for="responder"><b>Mei</b></label>
<input type="checkbox" name="responder" value="Mei" id="responder">
<label for="responder"><b>Random</b></label>
<input type="checkbox" name="responder" value="Random" id="responder">
</div>
<div id="submit" class="fluid">
<input type="submit" value="Submit">
</div>
</form>
and here's the php:
<?php
$emailBody= 'problem: '.$_POST['problem']."\n".
'email: '.$_POST['email']."\n".
'publish: '.$_POST['publish']."\n".
'responder: '.$_POST['responder']."\n"
if(isset($_POST['submit'])) {
mail('testing#gmail.com', 'problem' , $emailBody);
header('location: thankyoupage.HTML');
}
else{
header('location: testing.html');
}
?>
The problems vary when I mess around with the code but it always has a problem with everything after the variable. The only way not to generate an error message is by making th variable at the end of the if else statements.
In this case shown above the form wont work at all it just takes me to a page that says "Object not found error 404". And on the php file it says there's an unexpected T_if but if I put a semi-colon at the end of the variable the script doesn't work at all. Help will be much appreciated and thank you in advance.
2 issues with your form and your handler. (N.B.: See my EDIT a little further down).
1) Form: Missing name for submit button <input type="submit" value="Submit">
Without it being named, your handler will never execute the mail() function.
2) PHP handler: Missing semi-colon at the end of 'responder: '.$_POST['responder']."\n"
Tested and working for me
HTML FORM
<form action="form2email.php" method="post">
<div id="problem" class="fluid">
<textarea name="problem" cols="50" rows="4" placeholder="enter problem here" row="4"></textarea>
</div>
<div id="email" class="fluid">
<input type="email" name="email" placeholder="email optional">
</div>
<div id="userOptions" class="fluid">
<label for="yes">Yes</label>
<input name="publish" type="radio" value="Yes">
<label for="no">No</label>
<input type="radio" name="publish" value="No">
<label for="responder"><b>Michael</b></label>
<input name="responder" type="checkbox" value="Michael" id="responder">
<label for="responder"><b>Jennifer</b></label>
<input type="checkbox" name="responder" value="Jennifer" id="responder">
<label for="responder"><b>Mei</b></label>
<input type="checkbox" name="responder" value="Mei" id="responder">
<label for="responder"><b>Random</b></label>
<input type="checkbox" name="responder" value="Random" id="responder">
</div>
<div id="submit" class="fluid">
<input type="submit" value="Submit" name="submit">
</div>
</form>
PHP handler
<?php
$emailBody= 'problem: '.$_POST['problem']."\n".
'email: '.$_POST['email']."\n".
'publish: '.$_POST['publish']."\n".
'responder: '.$_POST['responder']."\n";
if(isset($_POST['submit'])) {
mail('testing#gmail.com', 'problem' , $emailBody);
header('location: thankyoupage.HTML');
}
else{
header('location: testing.html');
}
?>
EDIT
Another thing I noticed is that you have multiple choices used as checkboxes.
There are a few more things that need to be added in order for it to work properly and show each checked box in the Email.
1) Using a foreach in the PHP handler:
foreach ($_POST['responder'] as $value) {
$check_msg .= "Checked: $value\n";
}
2) Adding brackets to treat each checkbox as an array:
I.e.: name="responder[]"
New Handler:
<?php
foreach ($_POST['responder'] as $value) {
$check_msg .= "Checked: $value\n";
}
$emailBody= 'problem: '.$_POST['problem']."\n".
'email: '.$_POST['email']."\n".
'publish: '.$_POST['publish']."\n".
'' . $check_msg . "\n";
if(isset($_POST['submit'])) {
mail('testing#gmail.com', 'problem' , $emailBody);
header('location: thankyoupage.HTML');
}
else{
header('location: testing.html');
}
?>
New form:
<form action="form2email.php" method="post">
<div id="problem" class="fluid">
<textarea name="problem" cols="50" rows="4" placeholder="enter problem here" row="4"></textarea>
</div>
<div id="email" class="fluid">
<input type="email" name="email" placeholder="email optional">
</div>
<div id="userOptions" class="fluid">
<label for="yes">Yes</label>
<input name="publish" type="radio" value="Yes">
<label for="no">No</label>
<input type="radio" name="publish" value="No">
<label for="responder"><b>Michael</b></label>
<input name="responder[]" type="checkbox" value="Michael" id="responder">
<label for="responder"><b>Jennifer</b></label>
<input type="checkbox" name="responder[]" value="Jennifer" id="responder">
<label for="responder"><b>Mei</b></label>
<input type="checkbox" name="responder[]" value="Mei" id="responder">
<label for="responder"><b>Random</b></label>
<input type="checkbox" name="responder[]" value="Random" id="responder">
</div>
<div id="submit" class="fluid">
<input type="submit" value="Submit" name="submit">
</div>
</form>
Choosing 3 names from the form will produce something similar to the following:
Checked: Jennifer
Checked: Mei
Checked: Random