Jump to content

Allow to add more fields to form...


Sparrz

Recommended Posts

:shrug:

 

I need help with a form ..

 

My form needs to allow an additional drop down field for Groups. This form also needs to save the extra fields chosen into my MySQL DB.

 

Here is my form..


<form action='' method='post' class='assessment'>
<h1>Create User</h1>
<div class='label'>First Name</div>
<div class='field'><input type='text' name='firstname' value='<?=$preUser->firstname?>' /></div>
<div class='cb'></div>
<div class='label'>Last Name</div>
<div class='field'><input type='text' name='lastname'  value='<?=$preUser->lastname?>' /></div>
<div class='cb'></div>
<div class='label'>Password</div>
<div class='field'><input type='text' name='password'  value='<?=$preUser->password?>' /></div>
<div class='cb'></div>
<div class='label'>Company</div>
<div class='field'><input type='text' name='company'  value='<?=$preUser->company?>' /></div>
<div class='cb'></div>
<div class='label'>Job Title</div>
<div class='field'><input type='text' name='job'  value='<?=$preUser->job?>' /></div>
<div class='cb'></div>
<div class='label'>Group Name</div>
<div class='field'><select name='group'><?=$groupSelect?></select></div>
<div class='cb'></div>
<div class='label'>Address</div>
<div class='field'><input type='text' name='street1'  value='<?=$preUser->street1?>' /></div>
<div class='cb'></div>
<div class='label'>Address (optional)</div>
<div class='field'><input type='text' name='street2'  value='<?=$preUser->street2?>' /></div>
<div class='cb'></div>
<div class='label'>City</div>
<div class='field'><input type='text' name='city'  value='<?=$preUser->city?>' /></div>
<div class='cb'></div>
<div class='label'>State</div>
<div class='field'><input type='text' name='state'  value='<?=$preUser->state?>' /></div>
<div class='cb'></div>
<div class='label'>Postal Code</div>
<div class='field'><input type='text' name='postal'  value='<?=$preUser->postal?>' /></div>
<div class='cb'></div>
<div class='label'>Country</div>
<div class='field'><input type='text' name='country'  value='<?=$preUser->country?>' /></div>
<div class='cb'></div>
<div class='label'>Fax</div>
<div class='field'><input type='text' name='fax'  value='<?=$preUser->fax?>' /></div>
<div class='cb'></div>
<div class='label'>Phone</div>
<div class='field'><input type='text' name='phone1'  value='<?=$preUser->phone1?>' /></div>
<div class='cb'></div>
<div class='label'>Phone 2</div>
<div class='field'><input type='text' name='phone2'  value='<?=$preUser->phone2?>' /></div>
<div class='cb'></div>
<div class='label'>Email</div>
<div class='field'><input type='text' name='email'  value='<?=$preUser->email?>' /></div>
<div class='cb'></div>
<div class='label'>Website</div>
<div class='field'><input type='text' name='website'  value='<?=$preUser->website?>' /></div>
<div class='cb'></div>
<div class='label'>Photo</div>
<div class='field imgupload'>
	<input type='hidden' name='photo' />
	<? if( $preUser->photo ){ ?>
		<img src="../<?=$preUser->photo?>" style="height:300px; float:left;" />
		<span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="<?=$preUser->photo?>">x</span>
	<? }else{ ?>
		<iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe>
	<? } ?>
</div>
<div class='cb'></div>
<div class='label'>Payment Option</div>
<div class='field'>
	<input type='radio' name='payment' value='Pay' <? if( $preUser->payment == 'Pay' ) echo "checked='checked'"; ?> />Pay<br />
	<input type='radio' name='payment' value='NonPaid' <? if( $preUser->payment == 'NonPaid' ) echo "checked='checked'"; ?> />NonPaid
</div>
<div class='cb'></div>
<div class='label'>Dashboard Options</div>
<div class='field'>
	<div><input type='checkbox' name='mysteps' <? if( $preUser->mysteps ) echo "checked='checked'"; ?> value='1' />My Steps</div>
	<div><input type='checkbox' name='mycalendar' <? if( $preUser->mycalendar ) echo "checked='checked'"; ?> value='1' />My Calendar</div>
	<div><input type='checkbox' name='myprofiles' <? if( $preUser->myprofiles ) echo "checked='checked'"; ?> value='1' />My Profile</div>
	<div><input type='checkbox' name='myplans' <? if( $preUser->myplans ) echo "checked='checked'"; ?> value='1' />My Plans</div>
</div>
<div class='cb'></div>
<div class='submit_assessment'><input type='submit' name='create_user' class='submit' value='Create User' /> <input type='button' value='Back' class='back' name='admin_create' /></div>
<div class='cb'></div>
</form>
<script>
function setUploadedImage(flink){
	$('.imgupload > input:first').after('<img src="../'+flink+'" style="height:300px; float:left;" /><span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="'+flink+'">x</span>');
	$('.imgupload > iframe:first').remove();
	$('.imgupload > input:first').val(flink);
}
$('.rmimage').live('click', function (){
	$(this).prev().prev().val('');
	$(this).prev().remove();
	$(this).after('<iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe>');
	$.post('../ajax/admin.php',{remove_image:$(this).attr("alt")});
	$(this).remove();
});
</script>

 

the specific area in question is this...

<div class='label'>Group Name</div>
<div class='field'><select name='group'><?=$groupSelect?></select></div>

 

I need to be able to add another dropdown list to allow for multiple group selections that get saved into the DB once submitted.

 

How do I go about doing this??????

 

 

Link to comment
Share on other sites

Maybe I was not clear in my explanation...

 

I need to have an add field button for the group section so that it creates a new field using the same field info. In other words I need to be able to add a new drop down there so I can choose multiple groups to the user.

 

But thank you for your quick resonse.. ;)

Link to comment
Share on other sites

well you have to post the data in order to get it into the database so that they can select that option and any others... So you will need to have them post the form first, then take them to a form to select the groups they want. before letting them finish signing up.

 

 

Link to comment
Share on other sites

The info for the Group field is posted in another form and saved into the DB, I just need to be able to call up the same field info and save this newly submitted form into the User Table in this DB and have the new field(s) saved into another new column in the DB.

 

I have a Table in the DB for Groups and another form that creates the New Groups already. The Group field used in this User Creation form reads from that table already.

Link to comment
Share on other sites

What about some thing like this?

		<?php
	$query = "SELECT * FROM your_db_table WHERE whatever = '".$whatever."' ORDER BY your_column_name ASC"; 
	$result = mysql_query($query) or die(mysql_error());
	echo '<select name="whatever_name[]" multiple="multiple">';
	while ($row = mysql_fetch_array($result)) {
			echo '<option value="">Select one or more</option>';
		if ($row['value'] == $value) {
			echo '<option value="'.$row['value'].'" SELECTED>'.$row['name'].'</option>';
		} else {
			echo '<option value="'.$row['value'].'">'.$row['name'].'</option>';
		}
	}
	echo '</select>';
	?>

of course you will need to check to make sure that they select something.

 

and then to parse it...

$test=$_POST['whatever_name'];
if ($test){
 foreach ($test as $t){
 coding to insert into db
 }
}

Link to comment
Share on other sites

All that to get an add field button?..There is no need for an SQL connect query as this is not having a problem connecting to the DB at all.

 

I just need to call up another field and once the form is submitted have it save to the Table for the user that this form creates.

Link to comment
Share on other sites

I basically need this to dynamically add the same Group field below the current one and once all the info is filled out get it to save to the user table in the DB under a new column. example .. Group1 and Group2...depending on how many new fields are created.

 

All DB connections are handled by a config file that is preloaded somewhere else.

Link to comment
Share on other sites

ic...

I thought you needed someway to get the selected data back to display the options so once it stored into the db they can select it for their choice.

 

How are you planning on getting the data, if you don't query the database for whatever they have submitted so far?

 

You keep saying "fields" so do you have a script that creates new "field" in your db or are you talking about just adding another row of data the the database?

 

If you are talking form fields then if they can create custom form fields then how are you storing the data into the db?

 

I'm just not getting what you are trying to do here...

 

Otherwise you will need to ask them how many "fields" they want and then they hit submit to build the form with the extra fields using an array to store the data until submitted or use ajax to do it dynamically without a page refresh.

 

If the latter is the case then post you question in a ajax forum.

 

 

Link to comment
Share on other sites

well the current Group field already brings up the Groups from the groups table in the DB, I just need a button next to this field so I can have the same field get called up for an additional group selection so for example if Group one was selected from the drop down menu, there would be an "Add another group" button next to it. Then if this is used and another group is selected it would get saved into another newly created column in the User Table which the form is already saving to. The column the the current group is being saved to is called group and it is using the id from the group table as the data in the user table.

 

But if a new field is used and a new group is selected then it would create a new column called group2..etc..depending on how many new fields are generated from the button...

 

if the button is hit twice it would generate two new fields directly under the current group field.

Link to comment
Share on other sites

In that case you would have to have them submit the form, then allow them to make another selection after it stored or used that information to pull the next set of options.

 

You would need to split up the form because you can't run a form inside a form.

 

I have a one page form that reorders the data up or down, edits, inserts anywhere in the list, moves it anywhere, or deletes the record, based on what they type in or select. And that has four different forms on the page. and four buttons "Up", "dn", "edit", and one "add/insert /move/delete/edit" button. With a lot of switches and ifelse statements for error checking. And for each selection there has to be submit and a page refresh. No other way around it. unless you use ajax or javascript.

 

So you would either have the the add fields at the bottom or the top of the form or have it skip showing any of the other data previously posted like name address or whatever.

 

From what you are describing I would try and get an ajax solution to make it less frustrating and faster for your end users to be able to wade through adding or selecting options or waiting for page refreshes.

 

 

 

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.