timmah1 Posted March 29, 2012 Share Posted March 29, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/259945-forms/ Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 you could display the matching resultset from the database, after it's inserted. that would let you match against numerical array values rather than dynamic element names. Quote Link to comment https://forums.phpfreaks.com/topic/259945-forms/#findComment-1332341 Share on other sites More sharing options...
timmah1 Posted March 29, 2012 Author Share Posted March 29, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/259945-forms/#findComment-1332375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.