Marty Walker Posted April 15, 2013 Share Posted April 15, 2013 Hi, I'm not sure if this is an API question but here goes. On a few recent sites I find myself creating the same sets of fields over and over - for a 'settings' page for example. Is there a way I can import/create a group of fields quickly? If you haven't seem Ryan's Form Builder there's a nifty import/export tool. That's what got me thinking about this. Cheers Marty 1 Link to comment Share on other sites More sharing options...
kongondo Posted April 15, 2013 Share Posted April 15, 2013 Not sure I understood, but this module by Ryan imports CSV files and supports importing of various fields. His site profile module possibly supports fields as well? Haven't used it, just reading this. Link to comment Share on other sites More sharing options...
Marty Walker Posted April 16, 2013 Author Share Posted April 16, 2013 I think that module only imports data into existing fields. And the 'issue' with the profile exporter is that it's an all or nothing approach - which is great - but I'm after a selective approach to adding multiple fields. For example my 'Settings' page would have anything from five to a dozen fields of various types: textfields for site name, email field for contact emails, check boxes for toggling sidebars on and off... the list goes on. 1 Link to comment Share on other sites More sharing options...
ryan Posted April 17, 2013 Share Posted April 17, 2013 I'm planning to bring the same import/export system that's in FormBuilder to Fields and Templates. 8 Link to comment Share on other sites More sharing options...
Luis Posted April 17, 2013 Share Posted April 17, 2013 My little workaround <?php if(!$input->post->import && !$fieldsImport && !$input->post->generate): ?> <hr /> <h4>Separate Fields by comma like this: i,am,a,new,field</h4> <form name="importform" method="post" action="./"> <div class="span3"> <p><label>Field Prefix?</label> <input type="text" name="prefix" /></p> </div> <div class="span3"> <p><label>Field Tag?</label> <input type="text" name="fieldtag" /></p> </div> <div class="span3"> <p><label>assign to </label> <select name="template"> <option></option> <?php foreach($templates as $singleTemplate): ?> <option value="<?php echo $singleTemplate->name ?>"><?php echo $singleTemplate->name ?></option> <?php endforeach ?> </select> </p> </div> <div class="span12"><textarea name="string"><?php echo $input->post->string ?></textarea><p><input type="submit" name="import" value="import" /></p></div> </form> <?php endif ?> <?php if($input->post->import){ $fieldsImport = $input->post->string; $fieldsImport = explode(',', $fieldsImport); } if($fieldsImport): ?> <hr /> <form name="fieldform" method="post" action="./"> <div class="row"><div class="span12"><hr /></div></div> <ul> <?php foreach($fieldsImport as $fieldNew): ?> <?php $alleTypes = '<select class="required" name="'.$fieldNew.'"> <option selected="selected" value=""/> <option value="Checkbox">Checkbox</option> <option value="Email">Email</option> <option value="File">File</option> <option value="Image">Image</option> <option value="Page">Page</option> <option value="Text">Text</option> <option value="Textarea">Textarea</option> <option value="URL">URL</option> </select>'; ?> <li><?php echo $fieldNew ?> <?php echo $alleTypes ?></li> <?php endforeach ?> </ul> <input type="hidden" value="<?php echo $input->post->prefix ?>" name="prefix" /> <input type="hidden" value="<?php echo $input->post->template ?>" name="template" /> <input type="hidden" value="<?php echo $input->post->fieldtag ?>" name="tag" /> <input type="submit" name="generate" value="generate" /> </form> <?php endif ?> <?php if($input->post->generate){ $prefix = $input->post->prefix; $tags = $input->post->tag; $template = $input->post->template; $addedFields = $fieldgroups->get('name='.$template); foreach($input->post as $key => $val){ if($key != 'prefix' && $key != 'tag' && $key != 'generate' && $key != 'template'){ $f = new Field; if($prefix){$f->name = $prefix.'_'.$key;}else{$f->name = $key;} $f->type = $val; $f->save(); $f->tags = '-'.$tags; $f->save(); $addedFields->add($f); $addedFields->save(); echo "$key = $val <br />"; } } } ?> 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now