Jump to content


Check out our Community Blogs

ethikz

Member Since 30 Aug 2010
Offline Last Active Mar 12 2013 05:08 PM
-----

Topics I've Started

Need help with form

02 November 2011 - 07:12 AM

I have searched and can't find anything to help me. I want to make it so if the element "satisfaction" is either x or y then it will display element "testimonial" if not then keep element "testimonial" hidden. This is what I have so far but it isn't working. Any help would be greatly appreciated

<form id="feedback-form" method="post" action="contactvalidate.php" action="javascript:alert('success!');">

			<label>Name</label><input class="required inpt" type="text" name="name" value="" /><br />
			<label>Company Name</label><input class="required inpt" type="text" name="companyname" value="" /><br />
			<label>E-Mail</label><input class="required inpt" type="text" name="email" value="" /><br />
			<label>Phone Number</label><input class="required inpt" type="text" name="phone" value="" /><br />
			<label style="margin-bottom:10px">Have you ordered from us?</label><input class="radio" type="radio" name="order" value="Yes" />Yes <input class="radio" type="radio" name="order" value="No" />No<br />
			<label>Your level of satisfaction</label>
				<select name="satisfaction" id="satisfaction" class="select">
					<option value="">--Select One--</option>
					<option value="Very Satisfied">Very Satisfied</option>
					<option value="Moderately Please">Moderately Pleased</option>
					<option value="Somewhat Dissatisfied">Somewhat Dissatisfied</option>
					<option value="Very Dissatisfied">Very Dissatisfied</option>
				</select><br />
			<!--  <input class="required inpt" type="text" name="subject" value="" /> --><br />
			<label>Comments</label><textarea class="textbox" name="message" rows="6" cols="30"></textarea><br />
			<label>Is it okay for us to use your comments as a testimonial in our marketing?</label><input class="radio" type="radio" name="testimonial" value="Yes" />Yes <input class="radio" type="radio" name="testimonial" value="No" />No<br />
			<label id="load"></label><input name="submit" type="image" class="btn" src="images/submit.gif" value="Send" />

		</form>
<!--end #footer--></div>
      
<script type="text/javascript">
function getIndex()
{
  var x=document.getElementById("satisfaction");
  if (x.selectedIndex == 'Very Satisfied' , 'Moderately Please');
   {
    $('#testimonial').show();
   }
  else
   {
    $('#testimonial').hide();
   }
}
</script>

Submitting AJAX signup results

26 September 2011 - 12:36 PM

I have an AJAX form and after someone signs up it validates and then posts to a DB. I am trying to figure out how to email the signup as well. Can I add another action="contact.php" to the form tag?

Any help would be appreciated

Here is the PHP
<?php
if($_GET['action'] == 'signup'){

mysql_connect('localhost','dbuser','dbpass');
mysql_select_db('dbname');

$email = mysql_real_escape_string($_POST['signup-email']);

if(empty($email)){
$status = "error";
$message = "You did not enter an email address!";
}
else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){
$status = "error";
$message = "You have entered an invalid email address!";
}
else {
$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
if(mysql_num_rows($existingSignup) < 1){

$date = date('Y-m-d');
$time = date('H:i:s');
$type = ($_POST['signup-type']);

$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time, signup_type) VALUES ('$email','$date','$time', '$type')");
if($insertSignup){
$status = "success";
$message = "You have been signed up!";
}
else {
$status = "error";
$message = "Ooops, There's been a technical error!";
}
}
else {
$status = "error";
$message = "This email address has already been registered!";
}
}

$data = array(
'status' => $status,
'message' => $message
);

echo json_encode($data);
exit;
}
?>


Here is the HTML
<form id="newsletter-signup" action="?action=signup" method="post">
<input type="text" name="signup-email" id="signup-email" class="fieldz" />
<input type="image" src="img/submit1.png" class="submitbtn" />
<input type="hidden" name="signup-type" value="Subject1" /></form><br /><p id="signup-response"></p>

<form id="newsletter-signup2" action="?action=signup" method="post">
<input type="text" class="fieldz" name="signup-email" id="signup-email" />
<input type="image" src="img/submit2.png" class="submitbtn" />
<input type="hidden" name="signup-type" value="Subject2" /></form><br /><p id="signup-response2"></p>



**Nevermind, I figured it out

Which field to post to DB statement

26 September 2011 - 10:13 AM

Alright I am having sort of an issue, maybe it is a brain **. I have 2 forms, 1 for one type of person and 1 for the other type of person. What I want to do is to determine which submit button is being pressed and then submit the proper type to the DB. So far I can only get it to post only 1 type. I know I am missing some code somewhere and maybe even a conditional statement or 2 but I can't pinpoint it. Any help would be appreciated it. If you need other code just let me know.

Here is the PHP
<?php
if($_GET['action'] == 'signup'){

mysql_connect('localhost','dbuser','dbpass');
mysql_select_db('dbname');

$email = mysql_real_escape_string($_POST['signup-email']);

if(empty($email)){
$status = "error";
$message = "You did not enter an email address!";
}
else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){
$status = "error";
$message = "You have entered an invalid email address!";
}
else {
$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
if(mysql_num_rows($existingSignup) < 1){

$date = date('Y-m-d');
$time = date('H:i:s');
$type = ($_POST['signup-type']);

$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time, signup_type) VALUES ('$email','$date','$time', '$type')");
if($insertSignup){
$status = "success";
$message = "You have been signed up!";
}
else {
$status = "error";
$message = "Ooops, There's been a technical error!";
}
}
else {
$status = "error";
$message = "This email address has already been registered!";
}
}

$data = array(
'status' => $status,
'message' => $message
);

echo json_encode($data);
exit;
}
?>


Here is the HTML
<form id="newsletter-signup" action="?action=signup" method="post">
<input type="text" name="signup-email" id="signup-email" class="fieldz" />
<input type="image" src="img/submit1.png" class="submitbtn" />
<input type="hidden" name="signup-type" value="Subject1" /></form><br /><p id="signup-response"></p>

<form id="newsletter-signup" action="?action=signup" method="post">
<input type="text" class="fieldz" name="signup-email" id="signup-email" />
<input type="image" src="img/submit2.png" class="submitbtn" />
<input type="hidden" name="signup-type" value="Subject2" /></form><br /><p id="signup-response"></p>



Thanks in advance

Free Wordpress Theme by Tech-Sect

28 August 2011 - 02:10 PM

Attached File  techsect_Big.jpg   28.54KB   44 downloads

Tech-Sect Web Solutions


Features:
W3C Complaint.
Browser compliant (IE7,8,9, FF 3+ Mac/PC, Safari 3+ Mac/PC, Opera 10+).
Blogging functionality
Portfolio functionality
Multiple widget areas
Theme Options page for easy customization of homepage.

Download:

Wordpress Themes | Tech-Sect


Please review my site

28 August 2011 - 08:20 AM

I have recently started a Web Solutions business and I would like input on design, accessibility and functionality.

Tech-Sect Web Solutions

Thanks

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download