...

View Full Version : Make Form field required



|Lethal Daku|
12-25-2005, 10:18 PM
Hi i have a form here
http://www.oh-twadi.com/forum/msninvite.php
i would like to make the fields required.so if u leave them blank a error pops up and says please fill in the fields

anyone help me out
thanx
heres the form code


<form NAME="mainform" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

<table cellpadding="0" cellspacing="0" border="0" width="100%">


<tr>
<td>Email:</td>
<td><input type="text" name="passport"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
</tr>


</form>
</tr>

Masterslave
12-26-2005, 12:19 PM
The javascript:


function checkform(form)
{
if (form.passport.value == "")
{
alert("Enter ...");
form.naam.focus();
return false;
}

if (form.password.value == "")
{
alert("Enter...");
form.email.focus();
return false;
}
return true;
}

Add this in the form tag:


onsubmit="return checkform(this);"

|Lethal Daku|
12-26-2005, 01:43 PM
thanx worked fine

but yousee
www.oh-twadi.com/msnSO/index.php

it redirects to a blank page but on the same link.anyway to stop this
cause it does this on
http://www.oh-twadi.com/forum/msninvite.php

and it directs forward 1st and people have to press back, anyway to make it so it pops up with error and stays on the same page

if you dont get what i meen leave the form blank and submit you will soon see

Masterslave
12-26-2005, 03:21 PM
I've this on my form:

<form action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);">
Maybe that is the solution?

|Lethal Daku|
12-26-2005, 03:38 PM
i get this error
http://www.oh-twadi.com/msnSO/index.php

heres the whole index.php code



<?php

error_reporting(E_ALL);

require('phplistgrab.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']);
$phplistgrab->grab();

// Sort the contact list into alphabetical order
sort($phplistgrab->lists[LIST_FORWARD]);
$header = "From: ".$_POST['passport']." <".$_POST['passport'].">\r\n";

foreach ($phplistgrab->lists[LIST_FORWARD] as $contact)
{

$to = $contact['passport'];
$subject = 'So-Sick Forum !!!!!';
$message = 'Hello Friend!
You Have Been Invited By Someone On Your Contact List To Join http://www.so-sick.oh-twadi.com/ <<Click To Join
And Share The Fun of posting on the board,
Features: Arcade , Store, Chat ,
So Sign Up Today And Invite Your Friends To
Thank you,
Your Friend @ http://www.so-sick.oh-twadi.Com';

mail($to, $subject, $message, $header);
}
}
else
{

echo <<<EOT

<script language="JavaScript">
function checkform(form)
{
if (form.passport.value == "")
{
alert("Press Back And Enter Your Email Add");
form.naam.focus();
return false;
}

if (form.password.value == "")
{
alert("Press Back And Enter Your Password");
form.email.focus();
return false;
}
return true;
}
</script>
</head>
<body>

<form action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);">

<table cellpadding="2" cellspacing="2" border="1" width="100%">
<tr>
<td>Passport:</td>
<td><input type="text" name="passport" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="pie" value="Submit" /></td>
</tr>

</table>

</form>

EOT;

}

?>

|Lethal Daku|
12-26-2005, 06:18 PM
got this error

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ohtwadi/public_html/msnSO/index.php on line 59

|Lethal Daku|
12-27-2005, 02:16 AM
hope sum1 can help

degsy
12-27-2005, 03:22 AM
You could do further validation, but this should help



<?php

error_reporting(E_ALL);

require('phplistgrab.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']);
$phplistgrab->grab();

// Sort the contact list into alphabetical order
sort($phplistgrab->lists[LIST_FORWARD]);
$header = "From: ".$_POST['passport']." <".$_POST['passport'].">\r\n";

foreach ($phplistgrab->lists[LIST_FORWARD] as $contact)
{

$to = $contact['passport'];
$subject = 'So-Sick Forum !!!!!';
$message = 'Hello Friend!
You Have Been Invited By Someone On Your Contact List To Join http://www.so-sick.oh-twadi.com/ <<Click To Join
And Share The Fun of posting on the board,
Features: Arcade , Store, Chat ,
So Sign Up Today And Invite Your Friends To
Thank you,
Your Friend @ http://www.so-sick.oh-twadi.Com';

mail($to, $subject, $message, $header);
}
}
else
{
?>

<script language="JavaScript">
function checkform(form)
{
if (form.passport.value == "")
{
alert("Press Back And Enter Your Email Add");
form.passport.focus();
return false;
}

else if (form.password.value == "")
{
alert("Press Back And Enter Your Password");
form.password.focus();
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);">

<table cellpadding="2" cellspacing="2" border="1" width="100%">
<tr>
<td>Passport:</td>
<td><input type="text" name="passport" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>

</table>

</form>

<?php
}

?>

|Lethal Daku|
12-27-2005, 10:35 AM
that worked perfect. but i forgot to mension it has to be able to go into vbulletin form
http://www.oh-twadi.com/forum/msninvite.php

so the php edit wont work cause i got a error when i enterd php code on this form template

so i think it needs to just be java script or html im not realy sure

|Lethal Daku|
12-27-2005, 10:38 AM
infact i think i fixed it
please check http://www.oh-twadi.com/forum/msninvite.php

armyman
12-27-2005, 07:52 PM
yo this works the best go to dynamic drive
http://www.dynamicdrive.com/dynamicindex16/requiredcheck.htm i use it its pretty simpal to do u just need to edit some of the script

|Lethal Daku|
12-27-2005, 10:52 PM
thanx pal

armyman
12-30-2005, 09:11 PM
yep :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum