form

radio.phps

<?
if ($_POST['submit']){

$ans=0;

echo ("Your answers: ");
echo ("There are ".$_POST['choice1']." days in a week.");
echo ("".$_POST['choice2']." is the first day of the week.");

if($_POST['choice1']=="7"){
$ans=$ans+1;
echo ("Your answer is correct! There are ".$_POST['choice1']." days in a week.");
}else{
echo ("Your answer is incorrect! There are not ".$_POST['choice1']." days in a week.

      Subscribe in a reader

checkbox.phps

<?php
if ($_POST['submit']){

$countsub=count($_POST['lista']);
for (
$i=0; $i < $countsub; $i++){
echo
"<br>".$_POST['lista'][$i];
}

}
else{
?>

" method=post>
Qué usted cree es el más importante de vida?
What do you believe is most important in life?

Comida [food]
Agua [water]
Abrigo [shelter]

      Subscribe in a reader

single.phps

<?php
if($_POST['submit'] && $_POST['myage'] && $_POST['difference']){
   
$total= $_POST['myage'] + $_POST['difference'];

echo
"My brother/sister is ".$total." years old.";

}else{
?>

" >

How old are you?

How many years older is your brother/sister?

      Subscribe in a reader

jscriptcheck2.phps

JavaScript Form Check

[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
for (var i = 0; i < string2.length; i++) {
if (iChars.indexOf(string2.charAt(i)) != -1)
return false;
}
return true;
}

//make check to see if the string only contains numbers, letters

      Subscribe in a reader

populate5.phps


<?php
if ($_POST['submit'] && $_POST['money']){
$dinero = implode($_POST['money'], ",");

$vals=explode(",",$dinero);
?>

How much money would you like to earn per week?

>100

200

      Subscribe in a reader

populate4.phps

<?php
if ($_POST['submit'] && $_POST['food']){
$favfood = $_POST['food'];
?>

<form method="post" action="populate4.php">
What is your favorite food to eat? <BR>
<TEXTAREA NAME="food" ROWS=5 COLS=35 wrap=virtual>
<?php echo $favfood?>
</TEXTAREA>
<input type="submit" name="submit" value="submit">
<form>
<?
}else{
?>
<form method="post" action="populate4.php">
What is your favorite food to eat? <BR>
<TEXTAREA NAME="food" ROWS=5 COLS=35 wrap=virtual></TEXTAREA>
<input type="submit" name="submit" value="submit">
</form>
<?
}
?>

      Subscribe in a reader

populate2.phps


<?php
if ($_POST['submit'] && $_POST['leap']){
$leapy = $_POST['leap'];
?>

A leap year occurs every 

<?
if ($leapy!="" && $leapy!="Select number") {
print $leapy;
print ("Select number");
} else {
print ("Select number");}
?>
1
2
3
4
5
6
7
years.

<?
}else{

      Subscribe in a reader

Populating checkboxes and select lists from an array

Populating checkboxes and select lists from an array

When you use checkboxes in a form, usually you want to save more than one choice.
You must indicate to PHP that you are submitting more than one piece of data with []

<INPUT TYPE="checkbox" NAME="temperature[]" VALUE="hot">Hot
<INPUT TYPE="checkbox" NAME="temperature[]" VALUE="cold">Cold

After submitting your form, save the array data into database.
You can use the implode function joins array elements into a string, then save that string to the
database.

PHP Code

      Subscribe in a reader

Form Processing with PHP: part 4

Form Validation

Validating a form

You can perform form validation before a form is submitted via JavaScript or after the form is submitted via PHP.

I've actually already demonstrated simple validation using PHP in Form Processing with PHP: Part 1, with the input.php script. After the form is submitted, the script checks to see whether a variable does or does not exist.

PHP Code:
<?php
//check if submit button clicked and the input field isn't empty, print hello
if ($submit == "click" && $UserName !=""):
echo "Hello, $UserName";

      Subscribe in a reader

Using forms with PHP: part 3

Form Processing with PHP: Part 3

How to populate form fields with previously submitted values.

When you see the scripts in action, take a look at the source code, especially what the values of the form fields are set to before and after the scripts execute.

Input field:

To automatically have the value of an input field filled out, use the echo/print function to place the value submitted into the value attribute of the field.

PHP Code:

<?php
if ($submit && $firstname){
$fname = $firstname;
?>

What is your first name?

      Subscribe in a reader
Syndicate content