/    Sign up×
Community /Pin to ProfileBookmark

Q: form validation & data received

Hi all,
I’m new in PHP, and I’ve surf the web and found some php code which I’ve use it in my webpage ([URL]http://www.foolishman.net/testphp.htm[/URL] ).
Now, I have some problems and want to seek for your kind help.
1/ how to validation selection box (the required field) to be selected (point 4 in the webpage);
2/ how to retain (pre-filled) the choice which the vistor has already selected after an error was found (say, if you only enter your NAME and select the Sex and then press ‘submit’, an error page is shown, but, the choice (I only know how to retain a textbox message) is missed);
3/ how to validate the data (point 6 to 9 in the webpage) need to be fill if ABC course (point 5 in the webpage) is selected, also the data (point 10) if DEF course (point 5 in the webpage) is selected;
4/ how can I get the all the [B]selected[/B] value of the checkbox group (point 5 in the webpage) in the email which send to me (I’ve test to select two or more checkbox, but, in the email, only the value of the [B]last one [/B] was shown).

Below is the PHP code (testphp_process.php) which I used for the webpage.
As I just gather and merge the code from the web, I’m not sure whether it is something confusing or duplicate or outdated, so, I’m very happy if anyone of you can have a look on it and give me some advices on the above problems and the code below. Thanks~~!

[code=php]<?php
function getAddress()
{
if(!empty($_SERVER[‘HTTP_CLIENT_IP’]))
{
$ip_expl = explode(‘.’, $_SERVER[‘HTTP_CLIENT_IP’]);
$referer = explode(‘.’, $_SERVER[‘REMOTE_ADDR’]);
if($referer[0] != $ip_expl[0])
{
$ip = array_reverse($ip_expl);
$return = implode(‘.’, $ip);
}
else
{
$return = $client_ip;
}
}
elseif(!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
{
if(strstr($_SERVER[‘HTTP_X_FORWARDED_FOR’], ‘,’))
{
$ip_expl = explode(‘,’, $_SERVER[‘HTTP_X_FORWARDED_FOR’]);
$return = end($ip_expl);
}
else
{
$return = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
}
else
{
$return = $_SERVER[‘REMOTE_ADDR’];
}
return $return;
}
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
if ($action == “send”)
{
include(“testphp_config.php”);
$ip = getAddress();
$to = $ademail;
$name = $_POST[‘student_name_eng’];
$from = $_POST[‘sender_email’];
$sex = $_POST[‘sex’];
$coursestotake = $_POST[‘applycourse’];

$to = trim($to);
$name = trim($student_name_eng);
$from = trim($from);
$sex = trim($sex);
$coursestotake = trim($applycourse);

if (empty($to))
{
$ermessage = “ERROR¡JEmail address to can not be blank, Please enter your email address in the config file!”;
include(“testphp_error.htm”); exit();
}
if (empty($name))
{
$ermessage = “ERROR: Please enter your name.”;
include(“testphp_error.htm”); exit();
}
if (empty($sex))
{
$ermessage = “ERROR: Please enter your sex.”;
include(“testphp_error.htm”); exit();
}
if (empty($coursestotake))
{
$ermessage = “ERROR: Please select one or more courses.”;
include(“testphp_error.htm”); exit();
}

$body =
“Application Form Details¡Jn_______________________________________n”.
“nStudent Name¡J”.$name.
“nSex¡J”.$sex.
“nEmail¡J”.$from.
“nCourse Apply¡J”.$coursestotake.
“n”.
“n************************************************************”.
“nDate and Time¡J”.date(“Y-m-d D H:i:s”).
“nIP¡J”.$ip.
“n************************************************************”;

$bodycopy =
“n************************************************************”.
“nAutorespond”.
“n************************************************************”.
“n”.
“n____________________________________________________________n”.
“nStudent Name¡J”.$name.
“nSex¡J”.$sex.
“nEmail¡J”.$from.
“nCourse Apply¡J”.$coursestotake.
“n____________________________________________________________n”.
“n”.
“n”.
“nThank you for your interest in our courses”.
“n”.
“n”.
“n”;

$send = mail($to, “applicationform”, $body, “From: $name”);
if ($send)
{
include(“testphp_thankyou.htm”);
// send copy of email to sender
mail(“$name<$from>”, “¡iAutorespond¡jThank you for your application¡I”,
$bodycopy, “From: XXXXXXX <$to>”);
exit();
}
else
{
$ermessage = “ERROR¡Jinformation cannot be send, please try again.”;
include(“testphp_error.htm”); exit();
}
}
else
{
include(“testphp.htm”);
}

?>[/code]

Below is the error page (testphp_error.htm).

[code=html]………
<form name=”applicationform” method=”post” action=”testphp_process.php?action=send”>
………………
<td colspan=”4″ rowspan=”1″ valign=”undefined”><font color=”red[COLOR=Red]”><?php echo $ermessage; ?>[/COLOR]</font></td>
………….
<td style=”width: 436px;” align=”undefined” valign=”undefined”>
<input size=”30″ name=”student_name_eng” [COLOR=Red]value=”<?php echo $name; ?>”[/COLOR]></td>
………………..
<td align=”undefined” valign=”undefined”><input name=”sex” value=”male” type=”radio”>Male</td>
<td align=”undefined” valign=”undefined”><input name=”sex” value=”female” type=”radio”>Female</td>
……………
<td align=”undefined” valign=”undefined”>
<input size=”30″ name=”sender_email” [COLOR=Red]value=”<?php echo $from; ?>”[/COLOR]></td>
…………………..
<td align=”undefined” valign=”undefined”>Year
of Birth</td>

<td align=”undefined” valign=”undefined”>
<select name=”dob_year”>
<option>Please select</option>
<option>1987</option>
……………….
</select>
……………………
<td style=”width: 200px;” align=”undefined” valign=”undefined”>Course Apply<br>

(You can select one or more courses)</td>
………………………
<td><input value=”abccourse” name=”applycourse” type=”checkbox”>ABC course
(complete point 6 to 9)</td>

<td align=”undefined” valign=”undefined”><input value=”defcourse” name=”applycourse” type=”checkbox”>DEF
course (complete point 10)</td>

<td><input value=”ghicourse” name=”applycourse” type=”checkbox”>GHI course</td>

<td align=”undefined” valign=”undefined”><input value=”jklcourse” name=”applycourse” type=”checkbox”>JKL
course</td>
………………
<td style=”width: 200px; background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>”ABC course
details”</td>
……………….
<td style=”width: 200px; background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>Days a week</td>
………………

<td align=”undefined” valign=”undefined”><input value=”one” name=”abccourse_day_per_week” type=”radio”>One
day</td>

<td><input value=”two” name=”abccourse_day_per_week” type=”radio”>Two days</td>

<td align=”undefined” valign=”undefined”><input value=”three” name=”abccourse_day_per_week” type=”radio”>Three
days</td>

<td><input value=”four” name=”abccourse_day_per_week” type=”radio”>Four days</td>

<td align=”undefined” valign=”undefined”><input value=”five” name=”abccourse_day_per_week” type=”radio”>Five
days</td>

……………
<td style=”background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>Day</td>
<td align=”undefined” valign=”undefined”><input value=”Mon” name=”abcevery_[]” type=”checkbox”>Every
Monday<br>

</td>

<td><input value=”Tue” name=”abcevery_[]” type=”checkbox”>Every Tuesday<br>

</td>

<td><input value=”Wed” name=”abcevery_[]” type=”checkbox”>Every Wednesday</td>

<td align=”undefined” valign=”undefined”><input value=”Thur” name=”abcevery_[]” type=”checkbox”>Every
Thursday</td>

<td align=”undefined” valign=”undefined”><input value=”Fri” name=”abcevery_[]” type=”checkbox”>Every
Friday</td>
……………
<td style=”background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>Start Time</td>

<select name=”abccourse_starttime”>
<option selected=”selected”>Please select</option>
<option>09:30</option>
…………….
</select>

start </td>
………..

<td style=”width: 200px; background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>Course Start Date</td>

<td style=”width: 436px; background-color: rgb(255, 255, 153);” align=”undefined” valign=”undefined”>
<td>
<select name=”abccourse_startdate_month”>
<option selected=”selected”>Please select</option>
<option>01</option>
…………………..
</select>

month</td>

<td align=”undefined” valign=”undefined”>
<select name=”abccourse_startdate_day”>
<option selected=”selected”>Please select</option>
<option>01</option>
…………………
</select>

day</td>

………………..
<td style=”background-color: rgb(255, 204, 204);” align=”undefined” valign=”undefined”>”DEF course
details”</td>
…………….
<td style=”background-color: rgb(255, 204, 204);” align=”undefined” valign=”undefined”>Main Subject<br>

(You can select one or all courses)</td>

…………………
input value=”English” name=”defcourse_subject[]” type=”checkbox”>English</td>

<td><input value=”Mathematics” name=”defcourse_subject[]” type=”checkbox”>Mathematics</td>
………………
<td style=”width: 436px;” align=”undefined” valign=”undefined”>
<input value=”Submit” name=”submit” type=”submit”>
<input value=”Reset” name=”reset” type=”reset”></td>[/code]

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@katasovaNov 10.2005 — hi there, u ask for a lot of things and some are nto so easy to explain, as u should notice my english is not so good but indeed i know some (or maybe all) the answears for ur questions....

I dont have enough time right now to tell u how to solve it but if u want u can send me an email to [email][email protected][/email] and tonight i can send u some samples that u can use to solve ur problems ?

If u dont want to send the mail to me i will try to look for this post later when i have some time and post what u want here, so take a look here in night if u still dont find what u need ?
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 11.2005 — hi there, u ask for a lot of things and some are nto so easy to explain, as u should notice my english is not so good but indeed i know some (or maybe all) the answears for ur questions....

I dont have enough time right now to tell u how to solve it but if u want u can send me an email to [email][email protected][/email] and tonight i can send u some samples that u can use to solve ur problems ?

If u dont want to send the mail to me i will try to look for this post later when i have some time and post what u want here, so take a look here in night if u still dont find what u need ?[/QUOTE]

THANKS, I've sent you an email. ?
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 12.2005 — 2/ how to retain (pre-filled) the choice which the vistor has already selected after an error was found (say, if you only enter your NAME and select the Sex and then press 'submit', an error page is shown, but, the choice (I only know how to retain a textbox message) is missed);
[/QUOTE]


I've added (in red color) the below code, and it can now prefill the choice, but, it only works for RADIO button.

.............

<td align="undefined" valign="undefined"><input name="sex" value="male" type="radio" [COLOR=Red]<?php if($sex==male){echo("checked="checked"");}?>[/COLOR] >Male</td>

<td align="undefined" valign="undefined"><input name="sex" value="female" type="radio" [COLOR=Red]<?php if($sex==female){echo("checked="checked"");}?>>[/COLOR]Female</td>

...........


I use the same method in the checkbox (see below code in red), only the last choice is prefilled (ie. when ABC course and DEF course are selected, after an error page is shown, only DEF course is prefilled; or when DEF course and JKL course are selected, only JKL is prefilled after an error page). So, any suggustion to solve it, please?

............

<td><input value="abccourse" name="applycourse" type="checkbox" [color=red]<?php if($coursestotake==abccourse){echo("checked="checked"");}?>[/color] >ABC course

(complete point 6 to 9)</td>

<td align="undefined" valign="undefined"><input value="defcourse" name="applycourse" type="checkbox" [color=red]<?php if($coursestotake==defcourse){echo("checked="checked"");}?>[/color] >DEF

course (complete point 10)</td>

<td><input value="ghicourse" name="applycourse" type="checkbox" [color=red]<?php if($coursestotake==ghicourse){echo("checked="checked"");}?>[/color] >GHI course</td>

<td align="undefined" valign="undefined"><input value="jklcourse" name="applycourse" type="checkbox" [color=red]<?php if($coursestotake==jklcourse){echo("checked="checked"");}?>[/color] >JKL

course</td>

.....................


I also want to know how to prefill the selection box (drop down list)?

Thanks!!
Copy linkTweet thisAlerts:
@bokehNov 12.2005 — [code=php]<?php ?>

<select name="dropdown" size="1">
<option value="val_1"<?php if($_POST == 'val_1') echo ' selected="selected"'; ?>>val 1</option>
<option value="val_2"<?php if($_POST == 'val_2') echo ' selected="selected"'; ?>>val 2</option>
</select>[/code]
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 13.2005 — [code=php]<?php ?>

<select name="dropdown" size="1">
<option value="val_1"<?php if($_POST == 'val_1') echo ' selected="selected"'; ?>>val 1</option>
<option value="val_2"<?php if($_POST == 'val_2') echo ' selected="selected"'; ?>>val 2</option>
</select>[/code]
[/QUOTE]


Thanks for you reply!

I've add it to my webpage as shown below, but, the drop down list can't prefill after the error page is shown. Is there any steps I missed??

Below is the extract of the testphp_error.htm
[code=html]<select name="dob_year" size="1">
<option value="Please_select" <?php if($_POST == 'Please_select') echo 'selected="selected"'; ?>>Please select</option>
<option value="1987" <?php if($_POST == '1987') echo 'selected="selected"'; ?>>1987</option>
<option value="1988" <?php if($_POST == '1988') echo 'selected="selected"'; ?>>1988</option>
<option value="1989" <?php if($_POST == '1989') echo 'selected="selected"'; ?>>1989</option>
<option value="1990" <?php if($_POST == '1990') echo 'selected="selected"'; ?>>1990</option>
<option value="1991" <?php if($_POST == '1991') echo 'selected="selected"'; ?>>1991</option>
<option value="1992" <?php if($_POST == '1992') echo 'selected="selected"'; ?>>1992</option>
<option value="1993" <?php if($_POST == '1993') echo 'selected="selected"'; ?>>1993</option>
<option value="1994" <?php if($_POST == '1994') echo 'selected="selected"'; ?>>1994</option>
<option value="1995" <?php if($_POST == '1995') echo 'selected="selected"'; ?>>1995</option>
<option value="1996" <?php if($_POST == '1996') echo 'selected="selected"'; ?>>1996</option>
<option value="1997" <?php if($_POST == '1997') echo 'selected="selected"'; ?>>1997</option>
<option value="1998" <?php if($_POST == '1998') echo 'selected="selected"'; ?>>1998</option>
<option value="1999" <?php if($_POST == '1999') echo 'selected="selected"'; ?>>1999</option>
<option value="2000" <?php if($_POST == '2000') echo 'selected="selected"'; ?>>2000</option>
<option value="2001" <?php if($_POST == '2001') echo 'selected="selected"'; ?>>2001</option>
</select>[/code]
Copy linkTweet thisAlerts:
@bokehNov 13.2005 — Sorry but there was an error in what I posted above. This is how I would print out the above block. [B]Tested and fully functional:[/B][code=php]<?php ?>

<select name="dob_year" size="1">
<option<?php
if(empty($_POST['dob_year'])) echo ' selected="selected"';
?>>Please select</option>
<?php
for($start = 1987, $end = 2001; $start <= $end; $start++){
echo '<option value="'.$start.'"';
if($_POST['dob_year'] == $start) echo ' selected="selected"';
echo '>'.$start."</option>n";
}
?>
</select>[/code]
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 14.2005 — Sorry but there was an error in what I posted above. This is how I would print out the above block. [B]Tested and fully functional:[/B][code=php]<?php ?>

<select name="dob_year" size="1">
<option<?php
if(empty($_POST['dob_year'])) echo ' selected="selected"';
?>>Please select</option>
<?php
for($start = 1987, $end = 2001; $start <= $end; $start++){
echo '<option value="'.$start.'"';
if($_POST['dob_year'] == $start) echo ' selected="selected"';
echo '>'.$start."</option>n";
}
?>
</select>[/code]
[/QUOTE]


Thanks for your answer, it works fine~~!!!!!! ?

I've added the above code in testphp_error.htm, and amended the "please select" line as shown below:
[code=html].......
<option value="Please_select" selected="selected">Please select</option>
......[/code]


In testphp.htm, I've amended:
[code=html]..........
<option value="Please_select" selected="selected">Please select</option>
.........[/code]


Also, I've added lines in testphp_process.php:
[code=php]......
$birth = $_POST['dob_year'];
........
if ($birth == "Please_select")
{
$ermessage = "ERROR: Please select your year of birth.";
include("testphp_error.htm"); exit();
}
.......[/code]


As I want the vistor to choose the Year, not "please select", so, I've made the above 3 amendments. (I don't know whether it is a suitable or a complicated method to do this.)

It works what I want, THANKS A LOT!!!!!!!!

By the way, might I ask whether you or anyone know how to prefill the checkbox group, as I can [B]only[/B] prefill the [B]last one[/B] box (if two or more boxes are selected, only the last one is prefilled)?

Thanks.

[URL=http://www.foolishman.net/testphp.htm]http://www.foolishman.net/testphp.htm[/URL]
Copy linkTweet thisAlerts:
@bokehNov 14.2005 — Post the code for the checkboxes!
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 14.2005 — Post the code for the checkboxes![/QUOTE]

Thanks for your reply, below is the code of the checkboxes from testphp_error.htm
[code=html]...........
<input value="abccourse" name="applycourse" type="checkbox" <?php if($coursestotake==abccourse){echo("checked="checked"");}?> >ABC course
(complete point 6 to 9)

<input value="defcourse" name="applycourse" type="checkbox" <?php if($coursestotake==defcourse){echo("checked="checked"");}?> >DEF
course (complete point 10)

<input value="ghicourse" name="applycourse" type="checkbox" <?php if($coursestotake==ghicourse){echo("checked="checked"");}?> >GHI course

<input value="jklcourse" name="applycourse" type="checkbox" <?php if($coursestotake==jklcourse){echo("checked="checked"");}?> >JKL
course
..........[/code]


In testphp_process.php:
[code=php].......
$coursestotake = $_POST['applycourse'];
......
$coursestotake = trim($coursestotake);
.......
if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}
.........[/code]
Copy linkTweet thisAlerts:
@bokehNov 14.2005 — $applycourse is now an array so it can hold the multiple values:[code=php]<input value="abccourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'abccourse');
?> >ABC course (complete point 6 to 9)

<input value="defcourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'defcourse');
?> >DEF course (complete point 10)

<input value="ghicourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'ghicourse');
?> >GHI course

<input value="jklcourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'jklcourse');
?> >JKL course


<?php
function checkbox($key, $value)
{
if(empty($_POST[$key])) return FALSE;
if(($value == $_POST[$key]) or (is_array($_POST[$key])
and in_array($value, $_POST[$key]))) return ' checked="checked"';
return FALSE;
}
?>[/code]
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 14.2005 — Thanks for your answer!!!

$applycourse is now an array so it can hold the multiple values:[code=php]<input value="abccourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'abccourse');
?> >ABC course (complete point 6 to 9)

<input value="defcourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'defcourse');
?> >DEF course (complete point 10)

<input value="ghicourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'ghicourse');
?> >GHI course

<input value="jklcourse" name="applycourse[]" type="checkbox" <?php
echo checkbox('applycourse', 'jklcourse');
?> >JKL course
[/code]
[/QUOTE]

I've amended and added the above code in testphp_error.htm

[code=php]
<?php
function checkbox($key, $value)
{
if(empty($_POST[$key])) return FALSE;
if(($value == $_POST[$key]) or (is_array($_POST[$key])
and in_array($value, $_POST[$key]))) return ' checked="checked"';
return FALSE;
}
?>[/code]
[/QUOTE]

Also, I've added the above code within <head></head> in testphp_error.htm

It works fine.

All the code need to put inside the html page, not php page, am I correct??
Copy linkTweet thisAlerts:
@bokehNov 14.2005 — [code=php]<?php
function checkbox($key, $value)
{
if(empty($_POST[$key])) return FALSE;
if(($value == $_POST[$key]) or (is_array($_POST[$key])
and in_array($value, $_POST[$key]))) return ' checked="checked"';
return FALSE;
}
?>[/code]
[/QUOTE]
This is a function and doesn't constitute part of the output. It can be placed at the top or bottom of your script and must be located outside any conditional statements.
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 14.2005 — This is a function and doesn't constitute part of the output. It can be placed at the top or bottom of your script and must be located outside any conditional statements.[/QUOTE]
Thanks for your answer! I've put it just above the javascript and within <head></head> in my html error page.

Just tested again, and found there is something wrong (in red color) with content of the email (the data from the form) which sent to me.

Below is the email content:

Application Form Details¡J

_______________________________________

Student Name¡Jddddddd

Sex¡Jmale

Email¡J

Year of Birth¡J2000

Course Apply¡J[COLOR=Red][B]Array[/B][/COLOR]


************************************************************
Date and Time¡J2005-11-14 Mon 21:00:06

IP¡Jxxx.xxx.xxx.xxx

************************************************************

Below is the php file (testphp_process.php) which contain the information:
[code=php].......
$coursestotake = $_POST['applycourse'];
......
$coursestotake = trim($coursestotake);
.......
if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}
.........
$body =
"Application Form Details¡Jn_______________________________________n".
"nStudent Name¡J".$name.
"nSex¡J".$sex.
"nEmail¡J".$from.
"nYear of Birth¡J".$birth.
"nCourse Apply¡J".$coursestotake.
"n".
"n************************************************************".
"nDate and Time¡J".date("Y-m-d D H:i:s").
"nIP¡J".$ip.
"n************************************************************";
.............
$send = mail($to, "applicationform", $body, "From: $name");
..........[/code]


Any steps I' missed??
Copy linkTweet thisAlerts:
@bokehNov 14.2005 — What makes you think that is javascript? In fact it is php and has nothing to do with javascript and should be placed where I suggested. Change this:[code=php].......
$coursestotake = $_POST['applycourse'];
......
$coursestotake = trim($coursestotake);
.......
if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}[/code]
To this:[code=php]$coursestotake = (!empty($_POST['applycourse'])) ? implode(', ', $_POST['applycourse']) : NULL;

if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}[/code]
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 14.2005 — What makes you think that is javascript? In fact it is php and has nothing to do with javascript and should be placed where I suggested.
[/QUOTE]

Sorry, my english is not good, and my presentation is not good also. Or, I misunderstood your messages. Actually, I've added your code in the html page (testphp_error.htm) like the below. Is it the place where you suggested??

<html>

<head>

<title></title>

<meta>

[COLOR=Red]<?php

function checkbox($key, $value)

{

if(empty($_POST[$key])) return FALSE;

if(($value == $_
POST[$key]) or (is_array($_POST[$key])

and in_array($value, $_
POST[$key]))) return ' checked="checked"';

return FALSE;

}

?> [/COLOR]


<script>

.....

</script>

</head>

<body>

......

.....




Change this:[code=php].......
$coursestotake = $_POST['applycourse'];
......
$coursestotake = trim($coursestotake);
.......
if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}[/code]
To this:[code=php]$coursestotake = (!empty($_POST['applycourse'])) ? implode(', ', $_POST['applycourse']) : NULL;

if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}[/code]
[/QUOTE]

THANKS, It works great!!!!!!!!
Copy linkTweet thisAlerts:
@wwhassuppauthorNov 15.2005 — Hi, I want to have further validation (if checkbox A is selected, radio A1, checkbox A2 and selection A3 cannot be empty; and, checkbox B is selected, checkbox B1 must fill in; etc.) and I've added some lines in testphp_process.php, but, it can't works (because I just use what I know to test what code to add in the PHP file). Can anyone help me?

[URL=http://www.foolishman.net/testphp.htm]http://www.foolishman.net/testphp.htm[/URL] (if ABC course in point 5 is selected, vistors need to fill in point 6 to 9; if DEF course is selected, fill in point 10)

[code=php].......
$coursestotake = (!empty($_POST['applycourse'])) ? implode(', ', $_POST['applycourse']) : NULL;
$dpw = $_POST['abc_course_day_per_week'];
$every= (!empty($_POST['abcevery_'])) ? implode(', ', $_POST['abcevery_']) : NULL;
............
$dpw = trim($dpw);
................
................
if (empty($coursestotake))
{
$ermessage = "ERROR: Please select one or more courses.";
include("testphp_error.htm"); exit();
}
if (!empty($coursestotake[0]))
{
if (empty($dpw))
{
$ermessage = "ERROR: Please select how many days a week you want to attend course.";
include("testphp_error.htm"); exit();
}
if (empty($every))
{
$ermessage = "ERROR: Please select which days of a week you want to attend course.";
include("testphp_error.htm"); exit();
}
}
.........[/code]
×

Success!

Help @wwhassupp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...