/    Sign up×
Community /Pin to ProfileBookmark

Javascript form help: repost form inputs if form does not pass validation

I have a form that shows different questions depending on what the user selects. My problem is, if the user doesn’t not make it through the forms validation, the inputs the user entered do not refill. The user would have to restart all over again, and I don’t want that to happen, but I cant figure out whats going on.

Here I posted my code below. Its too long so I will post the rest in the next post, thankyou for your help! This is driving me crazy.

[CODE]<?
$additionalDetails = $_POST[‘details’];
$backInformation = $_POST[‘backInformation’];
$deadline = $_POST[‘deadline’];
$designIdeas = $_POST[‘ideas’];
$email = $_POST[’email’];
$emailSubject = ‘WetGFX Quote’;
$extra = $_POST[‘extra’];
$frontInformation = $_POST[‘frontInformation’];
$headers = “From: $emailrn”;
$headers .= “Content-type: text/htmlrn”;
$logoText = $_POST{‘logoText’};
$myspaceName = $_POST[‘myspaceName’];
$name = $_POST[‘name’];
$other = $_POST[‘other’];
$project = $_POST[‘project’];
$projectPurpose = $_POST[‘purpose’];
$sectionType = $_POST[‘sectionType’];
$sizingIrregular = $_POST[‘sizingIrregular’];
$sizingFB = $_POST[‘sizingFB’];
$sizingSides = $_POST[‘sizingSides’];
$sizingTB = $_POST[‘sizingTB’];
$urlname = urlencode($$_POST[‘name’]);

$message = “”;
$emailclass = “basictext”;
$username = “”;

// check project type selection
$projectSelection = $_POST[‘project’];
$brochureSelect = ‘unchecked’;
$businessCardSelect = ‘unchecked’;
$CDcoverSelect = ‘unchecked’;
$flyerSelect = ‘unchecked’;
$logoSelect = ‘unchecked’;
$myspaceSelect = ‘unchecked’;
$productPackagingSelect = ‘unchecked’;
$websiteSelect = ‘unchecked’;
$otherSelect = ‘unchecked’;

if ($projectSelection == ‘Brochure’) {
$brochureSelect = ‘checked’;

}
else if ($projectSelection == ‘Business Card’) {
$businessCardSelect = ‘checked’;
}
else if ($projectSelection == ‘CD Cover’) {
$CDcoverSelect = ‘checked’;
}
else if ($projectSelection == ‘Flyer’) {
$flyerSelect = ‘checked’;
}
else if ($projectSelection == ‘Logo’) {
$logoSelect = ‘checked’;
}
else if ($projectSelection == ‘Myspace’) {
$myspaceSelect = ‘checked’;
}
else if ($projectSelection == ‘Product Packaging’) {
$productPackagingSelect = ‘checked’;
}
else if ($projectSelection == ‘Website’) {
$websiteSelect = ‘checked’;
}
else if ($projectSelection == ‘Other’) {
$otherSelect = ‘checked’;
}

// check amount of sides selection
$sidesSelection = $_POST[‘sides’];

if ($sidesSelection == ‘oneSide’) {
$oneSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘twoSide’) {
$twoSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘threeSide’) {
$threeSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘fourSide’) {
$fourSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘fiveSide’) {
$fiveSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘sixSide’) {
$sixSideSelect = ‘selected’;
}
else if ($sidesSelection == ‘moreSide’) {
$moreSideSelect = ‘selected’;
}

// check section amount selection
$sectionAmount = $_POST[‘sections’];

if ($sectionAmount == ‘oneSection’) {
$sectionAmount1 = ‘selected’;
}
else if ($sectionAmount == ‘twoSection’) {
$sectionAmount2 = ‘selected’;
}
else if ($sectionAmount == ‘threeSection’) {
$sectionAmount3 = ‘selected’;
}
else if ($sectionAmount == ‘fourSection’) {
$sectionAmount4 = ‘selected’;
}
else if ($sectionAmount == ‘fiveSection’) {
$sectionAmount5 = ‘selected’;
}
else if ($sectionAmount == ‘moreSection’) {
$sectionAmountMore = ‘selected’;
}

if ($_POST[‘formValidation’] == 1) {
if (!ereg(“^[^@]{1,64}@[^@]{1,255}$”, $email))
{ // character and @ check
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;
$email_array = explode(“@”, $email);
$local_array = explode(“.”, $email_array[0]);

for ($i = 0; $i < sizeof($local_array); $i++)
{
if(!ereg(“^(([A-Za-z0-9!#$%&’*+/=?^_`{|}~-][A-Za-z0-9!#$%&
&#8618;’*+/=?^_`{|}~.-]{0,63})|(“[^(\|”)]{0,62}”))$”,
$local_array[$i]))
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;
$email_array = explode(“@”, $email);
$local_array = explode(“.”, $email_array[0]);

for ($i = 0; $i < sizeof($local_array); $i++)
{
if(!ereg(“^(([A-Za-z0-9!#$%&’*+/=?^_`{|}~-][A-Za-z0-9!#$%&
&#8618;’*+/=?^_`{|}~.-]{0,63})|(“[^(\|”)]{0,62}”))$”,
$local_array[$i]))
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;
if (!ereg(“^[?[0-9.]+]?$”, $email_array[1]))
{ //ip check
$domain_array = explode(“.”, $email_array[1]);

if (sizeof($domain_array) < 2) {
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;}//end if

for ($i = 0; $i < sizeof($domain_array); $i++)
{
if (!ereg(“^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
&#8618;([A-Za-z0-9]+))$”,
$domain_array[$i])) {
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;
if (!$email) { // blank input check
$message = “Please enter a valid email address.”;
$name = $_POST[‘name’];
$emailclass = “errortext”;}
}//end blank input check
}//end for
}//end ip check
}
}
} // end of character and @ check.

else if // valid form send
($projectSelection == ‘Brochure’){
mail($webMaster , $emailSubject, $body, $headers);
header(“location: quotecomplete.html”);
}// end send form

} // end formValidation

?>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@wetgfxauthorMay 29.2010 — [code]
<head>

<script language="JavaScript" src="calendar/calendar_us.js"></script>
<link rel="stylesheet" href="calendar/calendar.css">
<link href="Scripts/siteStyle.css" rel="stylesheet" type="text/css" />

</head>

<body onLoad="checkProject();">

<script type="text/javascript">

function checkProject() {
document.getElementById('brochureForm').style.display = 'none';
var elems = document.getElementsByName("project");
document.getElementById('brochureForm').val
for(var i=0; i < elems.length; i=i+1) {
if(elems[i].checked && elems[i].value == "Brochure") {
document.getElementById ('brochureForm').style.display = 'block';
i = elems.length;
}
}
}

function projectSelection(elemId) {
if(document.getElementById(elemId).value == "Brochure") {
document.getElementById ('brochureForm').style.display = 'block';
} else {
document.getElementById ('brochureForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Business Card") {
document.getElementById ('businessCardForm').style.display = 'block';
} else {
document.getElementById ('businessCardForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "CD Cover") {
document.getElementById ('CDcoverForm').style.display = 'block';
} else {
document.getElementById ('CDcoverForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Flyer") {
document.getElementById ('flyerForm').style.display = 'block';
} else {
document.getElementById ('flyerForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Logo") {
document.getElementById ('logoForm').style.display = 'block';
} else {
document.getElementById ('logoForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Myspace") {
document.getElementById ('myspaceForm').style.display = 'block';
} else {
document.getElementById ('myspaceForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Product Packaging") {
document.getElementById ('productPackagingForm').style.display = 'block';
} else {
document.getElementById ('productPackagingForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Website") {
document.getElementById ('websiteForm').style.display = 'block';
} else {
document.getElementById ('websiteForm').style.display = 'none';
}
if(document.getElementById(elemId).value == "Other") {
document.getElementById ('otherForm').style.display = 'block';
} else {
document.getElementById ('otherForm').style.display = 'none';
}
}

</script>


<form name="quote" action="http://www.wetgfx.com/quotecheckTRIAL.php" method="post">
<?
if ($message != "") {
print '<span class="errortext">'.
$message."<span><br>n";
}

?><BR>

<div id='projectQuestion'>
<table class="formLine1" width="550px">
<tr><TD>
What would you like to order?<BR></td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Brochure" id="projectChoice1" <?PHP print $brochureSelect; ?> >
Brochure
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Business Card" id="projectChoice2" <?PHP print $businessCardSelect; ?> >
Business Card
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="CD Cover" id="projectChoice3" <?PHP print $CDcoverSelect; ?>>
CD Cover
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Flyer" id="projectChoice4" <?PHP print $flyerSelect; ?>>
Flyer
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Logo" id="projectChoice5" <?PHP print $logoSelect; ?>>
Logo
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Myspace" id="projectChoice6" <?PHP print $myspaceSelect; ?>>
Myspace
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Product Packaging" id="projectChoice7" <?PHP print $productPackagingSelect; ?>>
Product Packaging
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Website" id="projectChoice8" <?PHP print $websiteSelect; ?>>
Website
</tr>
</td>
<tr>
<td>
<input onClick="projectSelection(this.id);" type="radio" name="project" value="Other" id="projectChoice9" <?PHP print $otherSelect; ?>>
Other
</tr>
</td>
</table>
</div>



<div id='brochureForm' style="display:none;">
<table width="550" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>*What will this brochure be for?</td>
<td><input name="purpose" width="200px" value="<? print $projectPurpose; ?>" type="text"></td>
</tr>

<tr class="formLine1">
<td>*How many sides will there be?<BR>
<span class="exampleText">(Front & Back = 2 sides)</span></td>
<td><select name='sides' >
<option value='selectOne'>Select one
<option <? $oneSideSelect ?> value='oneSide'>1
<option <? $twoSideSelect ?> value='twoSide'>2
<option <? $threeSideSelect ?> value='threeSide'>3
<option <? $fourSideSelect ?> value='fourSide'>4
<option <? $fiveSideSelect ?> value='fiveSide'>5
<option <? $sixSideSelect ?> value='sixSide'>6
<option <? $moreSideSelect ?> value='moreSide'>More
</select></td>
</tr>
<tr>
<td>Additional details:<BR>
<span class="exampleText">(If applicable)</span></td>
<td><textarea name="details" cols="30"><? print $additionalDetails; ?></textarea></td>
</tr>

<tr class="formLine1">
<td>Design Ideas:<BR>
<span class="exampleText">(If you have any preferences)</span></td>
<td><textarea name="ideas" cols="30"><? print $designIdeas; ?></textarea></td>
</tr>

<tr>
<td>When do you need this project completed?</td>
<td><input type="text" name="deadline" value="<? print $deadline; ?>" width="200px"/>
<script language="JavaScript">
new tcal ({
// form name
'formname': 'quote',
// input name
'controlname': 'deadline'
});
</script></td>
</tr>

<tr class="formLine1">
<td>*Your Name:</td>
<td><input name="name" type="text" width="200px" value="<? print $name; ?>"></td>
</tr>

<tr>
<td>*Your E-Mail address:</td>
<td><input name="email" type="text" width="200px" <? print $emailclass; ?>></td>
</tr>
</table>
</div>

</table>
<br>
<table>
<tr><TD align="right">
*Required Input
</TD></tr>
<td align="right"><tr>
<input type="hidden" name="formValidation" value="1">
<input type="submit" name="Button1" value="Submit">
</tr></td>
</table>
</form>
[/CODE]
×

Success!

Help @wetgfx 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.20,
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,
)...