Forum Moderators: coopster

Message Too Old, No Replies

jacks formmail completed fields create error as missing

         

markasread

1:12 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



Hi
I hope someone can help. Im completely new to PHP and am having a problem with a mail form.

Ive used Jacks formmail which i edited to work with register globals off after reading a post online.

Everything works great except for when i try to make certain fields required. The form produces an error saying the fields are missing even if they are filled in. The blog mentions a solution but hasnt put one up. If anyone can help i would really appreciate it

My HTML is below. the form is standard jacks formmail with the changes outlined in the link above.

<form method="post" id="form" onsubmit="return checkform(this);" action="url of form goes here">
<input type=hidden name="redirect" value="redirect page goes here">
<input type=hidden name="required" value="email,telephone">
<img src="images/stories/3step.jpg" alt="Currency rate finder">

<p>Rates change every second and our One Minute form is the best way to find live no obligation quotes for currency from the major currency providers. Complete the form then sit back and relax while we do the hard work.</p>
<p class="form_field">
<label for="name" class="required">Name</label><br/>
<input type="text" value="" name="name" id="name" />
</p>

<p class="form_field">
<label for="telephone" class="required">Telephone</label><br/>
<input type="text" value="" name="telephone" id="telephone" />
</p>

<p class="form_field">
<label for="mobile">Mobile</label><br/>
<input type="text" value="" name="mobile" id="mobile" />

</p>
<p class="form_field">
<label for="email" class="required">Email</label><br/>
<input type="text" value="" name="email" id="email" />
</p>

<p class="form_field">
<label for="currency_type" class="required">Currency Type</label><br/>

<select name="currency_type" id="currency_type" class="turnintodropdown">
<option>Select ...</option>
<option>UK Pounds</option>
<option>Euros</option>
<option>US Dollars</option>

<option>Australian Dollars</option>

<option>New Zealand Dollars</option>
<option>Canadian Dollars</option>
<option>South African Rand</option>
<option>Hong Kong Dollars</option>
<option>UAE Dirhams</option>

<option>Other</option>

</select>
</p>
<p class="form_field">
<label for="amount" class="required">Amount</label><br/>
<input type="text" value="" name="amount" id="amount" />
</p>
<p class="form_field">
<label for="quotes" class="required">How many currency providers would you like to contact you. (default = 1, maximum = 5) </label><br/>

<select name="quote" id="quote" class="turnintodropdown">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>

</select>
</p>
<div class="clearfix"></div>

<p>
<label for="comments">Comments</label><br/>
<textarea name="comments" id="comments" rows="10" cols="68"></textarea>
</p>

<p>
<input type="submit" id="submit" value="SUBMIT" />
</p>
<div class="clearfix"></div>
<div style="clear:both;"></div>

</form></div>

[edited by: jatar_k at 1:40 pm (utc) on June 30, 2009]
[edit reason] no urls thanks [/edit]

jatar_k

1:44 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld markasread,

that blog post may have helped but is not so good, sooo

let's start with a single example and see if we can't help

which field(s) are you trying to make required? How are those fields being checked in the formmail script? You don't need to paste the whoe script, just the part where it checks the posted values.

markasread

1:48 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



at the very least im trying to make the email and phone fields required. As i said before im completely new to PHP (thats why im using prepackaged forms) so forgive me if this isnt the correct bit.


// This is because I originally had it require but too many people
// were used to Matt's Formmail.pl which used required instead.
if ($required)
$require = $required;
// handle the required fields
if (isset($_POST['require'])¦isset($_POST['required'])) {
// seperate at the commas
$require = ereg_replace( " +", "", isset($_POST['required'])?$_POST['required']:$_POST['require']);
$required = split(",",$require); for ($i=0;$i<count($required);$i++) {
$string = trim($required[$i]);
// check if they exsist
if((!(${$string})) ¦¦ (!(${$string}))) {
// if the missing_fields_redirect option is on: redirect them
if ($missing_fields_redirect) {
header ("Location: $missing_fields_redirect");
exit;
}
$require;
$missing_field_list .= "<b>Missing: $required[$i]</b><br>\n";
}
}
// send error to our mighty error function
if ($missing_field_list)
print_error($missing_field_list,"missing");

markasread

1:56 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



Ive just realised that isnt the correct bit after all

// our mighty error function..
function print_error($reason,$type = 0) {
build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
// for missing required data
if ($type == "missing") {
if ($missing_field_redirect) {
header("Location: $missing_field_redirect?error=$reason");
exit;
} else {
?>
The form was not submitted for the following reasons:<p>
<ul><?
echo $reason."\n";
?></ul>
Please use your browser's back button to return to the form and try again.<?
}
} else { // every other error
?>
The form was not submitted because of the following reasons:<p>
<?
}
echo "<br><br>\n";

exit;

jatar_k

1:58 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think you would be better off adding your own error checking

maybe this thread could help a little, it covers the basics
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]

you have 8 fields, error checking could be done in 8 simple lines

markasread

2:06 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



thanks ill have a look.

jatar_k

2:24 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



some of those form processors make it very complicated because they are built for every form ever created. You are only really worried about yours.

Give it a read and see, I/we can give you a hand too