Jump to content

Forms


timmah1

Recommended Posts

We have this form that customers can make their own contact forms, and then it gets inserted to the database.

We can show the forms with no problems, the problem lies when someone hits submit, how do I echo out the values of the form when I'm not sure what the input name or id is going to be?

 

This sample form generated this code

<div class="element">
<label id="label-element-3" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;">
<span class="labelelementvalue">Email</span>
<span class="required">*</span></label>
<div class="errormessage" id="errormessage-element-3"></div>
<div class="option-container">
<input class="af-inputtext af-email af-formvalue  " type="text" name="element-3" id="element-3" value="" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:260px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;"></div>
</div>
<div class="element">
<label id="label-element-4" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;">
<span class="labelelementvalue">Textarea</span></label>
<div class="errormessage" id="errormessage-element-4"></div>
<div class="option-container">
<textarea class="af-textarea af-formvalue  " name="element-4" id="element-4" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:300px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;" rows="6"></textarea></div>
</div>
<div class="element">
</div>

 

If you notice, each input type is named "element-" with a number afterwards.

 

So each input could be like "element-4", "element-21", and so forth.

 

How would I post those values of the input fields when they are automatically named?

 

Thanks in advance

Link to comment
Share on other sites

I figured it out by just changing the input name to "element[]"

 

for($i=0; $i < count($_GET['element']); $i++){
      $vars = ($_GET['element'][$i] . "<br> ");
}

 

My next question, which may not being here, and I apologize in advance if posting this here is the wrong place, is dealing with the send function, which is done a jquery

 

I need to pass each $vars into the js form, and I have no idea how to do that.

 

That form looks like so

var firstname = $contactform.find('input[name="firstname"]').val();
	var surname = $contactform.find('input[name="surname"]').val();
	var state = $contactform.find('select[name="state"]').val();
	var mobilephone = $contactform.find('input[name="mobilephone"]').val();
	var email = $contactform.find('input[name="email"]').val();
	var message = $contactform.find('textarea[name="message"]').val();	
	var color = $contactform.find('input[name="color"]').val();

	//submit the form
	$.ajax({
		type: "GET",
		url: url,
		data: {firstname:firstname, surname:surname, state: state, mobilephone: mobilephone, email: email, message: message, color:color},
            success: function (data) {
			if (data && 'success') {
				// show thank you
				$contactpage.find('.contact-thankyou').show();
				$contactpage.find('.contact-form').hide();
			}  else {
				alert('Unable to send your message. Please try again.');
			}
		}

 

I need those var to just be the value of my $vars, then put them in the data:

 

Would I go about it this way?

var element[] = $contactform.find('input[name="element[$i]"]').val();

 

Then the data like:

data: {element:element[]},

 

How would I go about doing this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.