Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

php form required fields

General discussions related to php

Moderators: macek, egami, gesf

php form required fields

Postby mixerstation » Sat Dec 15, 2012 5:09 am

Hello everybody :)

I have one question, how to set the error for requiered fields? For example, if (in my case) birth year is not choosen, redirect to error.php( i do it ), but i want to that field is with red, and error in the bottom of the page(please fill (again in my case) birth year) ?

Code: Select all
<?php
    function write_data($label,$start,$end)
{
   if($label=="birth_year")
   echo "birth year: <select name=\"$label\">\n";
   else
   echo "$label: <select name=\"$label\">\n";
   echo "<option value=>choose</option>\n";
   $i=$start;
   while($i>=$end)
   {
   echo "<option value=\"$i\">$i</option>\n";
   $i--;
   }
   echo "</select>\n";
}
    write_data("birth_year",1992,1900);
    write_data("month",12,1);
    write_data("day",31,1);
?>

and my only with error text code
Code: Select all
<?php
$p="";
$p=$_GET["order_error"];
if ($p==1)
   echo '<br /><span id="error">Please fill all fields</span>';
?>


With css I format #error.
mixerstation
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Dec 15, 2012 5:02 am

Re: php form required fields

Postby faust » Sat Dec 15, 2012 5:36 am

What validation do you need? Server side or client side. If you think about client side with ajax, you will need some knowledge with ajax and it is absolutely necessary for security reasons to do server-side validation. Give more info and I think I can explain what you need tomorrow, cuz today it's a freakin busy day... Cheers !
faust
New php-forum User
New php-forum User
 
Posts: 109
Joined: Thu May 03, 2012 7:22 am

Re: php form required fields

Postby mixerstation » Sat Dec 15, 2012 5:46 am

ajax is not the best knowledge of me :D

I just want write an error in bottom(i did that) and that field which isn't choosen make red, or have a red "*"
mixerstation
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Dec 15, 2012 5:02 am


Return to PHP General

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron