/    Sign up×
Community /Pin to ProfileBookmark

PHP form help

Hi folks!

Created a simple form for registrations for events. Is there any way in PHP to hide data that is left blank by the user when they submit the form? There are lots of options on the form that players may not use and if they do not fill it out and I would like the form to not send that information to make the email easier to read.

Cheers!
Cory

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@RodionGorkMar 07.2012 — Hi! Your explanations are bit too hasty. Do I understand correctly that:

- you have a page with a form (possibly, generated by PHP, or static HTML);

- data from this form are sent to some server-side script (PHP?);

- this script after receiving data sends some template-generated e-mail with names, dates etc. substituted according to received data;

- and you want to exclude from e-mail template some parts for which there are no data from the form?

If so, then answer last question - what do you use for generating letter - if simple PHP template, then it is easy, you need to make changes like these:

[CODE]
// old variant
echo "Dear mr. $namen";
echo "you are invited to the party ";
echo "with your wife mrs. $wife";

// new variant
echo "Dear mr. $namen";
echo "you are invited to the party ";
if ($wife != "") {
echo "with your wife mrs. $wife";
}
[/CODE]


However it is senseless to discuss while we do not know exactly which way of e-mail generation are you using.
Copy linkTweet thisAlerts:
@mythicauthorMar 07.2012 — The form is generated in PHP.

Here is the form itself:http://www.alliancealberta.ca/forms/forms/form1.html

Once it submits it goes through a PHP process script to send an email form to me. The output looks like so:

Your Name: <name removed>

email address: <email removed>

date: March Masquerade

Event Position: PC

Character Being Played: Klanganor Ruincarver Orchunter

Any Diet Restrictions (forward to Abbey): None

Unspent Build Points?: No

Spending BP on:

Unspent Production Points?: Yes

Spending PP on: As much armour as I can get

Unspent Gobbies?: Yes

Spending Gobbies on: Can I get that march month pass thingy so that we get extra exp?

Magic Item 1:

MI1 Effects:

Magic Item 1:

MI2 Effects:

Magic Item 3:

MI3 Effects:

Magic Item 4:

MI4 Effects:

Magic Item 5:

MI5 Effects:

High Magic?:

HM Spends:

Celestial Spell 1:

Spell 1 qty:

Celestial Spell 2:

Spell 2 qty:

<shortened by me>

Earth Magic Spell 1: 1st --- Level

Spell 1 qty:

Earth Magic Spell 2: 1st --- Level

<shortened by me>

Anything Else?: Was wondering what gobbies we got for donating that clothing? Also

I'm hoping to learn critical attack. ? Thanks

So as you can see it sends a lot of information currently that players do not fill out (and they may never).

What I would like to do is if the information is left blank, the form does not send it. It would just cut down on the "clutter"

Hope that helps.
Copy linkTweet thisAlerts:
@mythicauthorMar 09.2012 — I did try the above code but have had no luck with the format change. All of the fields still appear in the email.

Here is the code for the PHP process

[code=php]<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','YourName');
pt_register('POST','emailaddress');
if($YourName=="" || $emailaddress=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([.-][a-z0-9]+)*)+"."\.[a-z]{2,}"."$",$emailaddress)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Your Name: ".$YourName."
email address: ".$emailaddress."
date: ".$date."
Event Position: ".$eventposition."
Character Being Played: ".$character."
Any Diet Restrictions (forward to Abbey): ".$dietrestriction."
Unspent Build Points?: ".$unspentbuildpoints."
Spending BP on: ".$spendingonBP."
Unspent Production Points?: ".$unspentproductionpoints."
Spending PP on: ".$spendingonPP."
Unspent Gobbies?: ".$unspentGS."
Spending Gobbies on: ".$spendingonGS."
Magic Item 1: ".$MagicItem1."
MI1 Effects: ".$Effect1."
Magic Item 1: ".$MagicItem2."
MI2 Effects: ".$Effect2."
Magic Item 3: ".$MagicItem3."
MI3 Effects: ".$Effect3."
Magic Item 4: ".$MagicItem4."
MI4 Effects: ".$Effect4."
Magic Item 5: ".$MagicItem5."
MI5 Effects: ".$Effect5."
High Magic?: ".$highmagicspends."
HM Spends: ".$spendingonHMagic."
Celestial Spell 1: ".$Celestial_Spell_List1."
Spell 1 qty: ".$QTYCS1."
Celestial Spell 2: ".$Celestial_Spell_List2."
Spell 2 qty: ".$QTYCS2."
Celestial Spell 3: ".$Celestial_Spell_List3."
Spell 3 qty: ".$QTYCS3."
Celestial Spell 4: ".$Celestial_Spell_List4."
Spell 4 qty: ".$QTYCS4."
Celestial Spell 5: ".$Celestial_Spell_List5."
Spell 5 qty: ".$QTYCS5."
Celestial Spell 6: ".$Celestial_Spell_List6."
Spell 6 qty: ".$QTYCS6."
Celestial Spell 7: ".$Celestial_Spell_List7."
Spell 7 qty: ".$QTYCS7."
Celestial Spell 8: ".$Celestial_Spell_List8."
Spell 8 qty: ".$QTYCS8."
Celestial Spell 9: ".$Celestial_Spell_List9."
Spell 9 qty: ".$QTYCS9."
Celestial Spell 10: ".$Celestial_Spell_List10."
Spell 10 qty: ".$QTYCS10."
Celestial Spell 11: ".$Celestial_Spell_List11."
Spell 11 qty: ".$QTYCS11."
Celestial Spell 12: ".$Celestial_Spell_List12."
Spell 12 qty: ".$QTYCS12."
Celestial Spell 13: ".$Celestial_Spell_List13."
Spell 13 qty: ".$QTYCS13."
Celestial Spell 14: ".$Celestial_Spell_List14."
Spell 14 qty: ".$QTYCS14."
Celestial Spell 15: ".$Celestial_Spell_List15."
Spell 15 qty: ".$QTYCS15."
Celestial Spell 16: ".$Celestial_Spell_List16."
Spell 16 qty: ".$QTYCS16."
Celestial Spell 17: ".$Celestial_Spell_List17."
Spell 17 qty: ".$QTYCS17."
Celestial Spell 18: ".$Celestial_Spell_List18."
Spell 18 qty: ".$QTYCS18."
Celestial Spell 19: ".$Celestial_Spell_List19."
Spell 19 qty: ".$QTYCS19."
Celestial Spell 20: ".$Celestial_Spell_List20."
Spell 20 qty: ".$QTYCS20."
Earth Magic Spell 1: ".$Earth_Spell_1."
Spell 1 qty: ".$QTYEM1."
Earth Magic Spell 2: ".$Earth_Spell_2."
Spell 2 qty: ".$QTYEM2."
Earth Magic Spell 3: ".$Earth_Spell_3."
Spell 3 qty: ".$QTYEM3."
Earth Magic Spell 4: ".$Earth_Spell_4."
Spell 4 qty: ".$QTYEM4."
Earth Magic Spell 5: ".$Earth_Spell_5."
Spell 5 qty: ".$QTYEM5."
Earth Magic Spell 6: ".$Earth_Spell_6."
Spell 6 qty: ".$QTYEM6."
Earth Magic Spell 7: ".$Earth_Spell_7."
Spell 7 qty: ".$QTYEM7."
Earth Magic Spell 8: ".$Earth_Spell_8."
Spell 8 qty: ".$QTYEM8."
Earth Magic Spell 9: ".$Earth_Spell_9."
Spell 9 qty: ".$QTYEM9."
Earth Magic Spell 10: ".$Earth_Spell_10."
Spell 10 qty: ".$QTYEM10."
Earth Magic Spell 11: ".$Earth_Spell_11."
Spell 11 qty: ".$QTYEM11."
Earth Magic Spell 12: ".$Earth_Spell_12."
Spell 12 qty: ".$QTYEM12."
Earth Magic Spell 13: ".$Earth_Spell_13."
Spell 13 qty: ".$QTYEM13."
Earth Magic Spell 14: ".$Earth_Spell_14."
Spell 14 qty: ".$QTYEM14."
Earth Magic Spell 15: ".$Earth_Spell_15."
Spell 15 qty: ".$QTYEM15."
Earth Magic Spell 16: ".$Earth_Spell_16."
Spell 16 qty: ".$QTYEM16."
Earth Magic Spell 17: ".$Earth_Spell_17."
Spell 17 qty: ".$QTYEM17."
Earth Magic Spell 18: ".$Earth_Spell_18."
Spell 18 qty: ".$QTYEM18."
Earth Magic Spell 19: ".$Earth_Spell_19."
Spell 19 qty: ".$QTYEM19."
Earth Magic Spell 20: ".$Earth_Spell_20."
Spell 20 qty: ".$QTYEM20."
Anything Else?: ".$extra_stuff."
";
$message = stripslashes($message);
mail("[email protected]","LARP Event Pre-Registration",$message,"From: Alliance Calgary PreRegistration Form");

header("Refresh: 0;url=http://www.alliancealberta.ca/contact_confirm.htm");
?><?php
}
?>[/code]
×

Success!

Help @mythic 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.18,
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,
)...