Jump to content
guy

Add markup to single field

Recommended Posts

Is there a method to add markup to a single input field when building a form?

At present I'd customise the forms markup:

$form = $modules->get("InputfieldForm");

$form->setMarkup([
    'item_content' => "{out}<span class='custom-span'></span>",
    ....
]);

Which works but adds the custom span to every inputFieldWrapper. Adjusting setMarkup on an individual field, i.e.

$field = $modules->get("InputfieldText");

$field->setMarkup([
    'item_content' => "{out}<span class='different-span'></span>"
]);

Calls the same method, setting $markup within inputFieldWrapper.php and adjusting the output of every inputFieldWrapper

Therefore I was hoping for a way of appending to the inputfield or wrapper without it being global

  • Like 1

Share this post


Link to post
Share on other sites

That's not possible right now, you could only use InputfieldMarkup before and after your inputfield to add wrapping markup around the whole inputfield.

  • Like 1

Share this post


Link to post
Share on other sites

no worries, thanks for letting me know

Share this post


Link to post
Share on other sites

what does inputfieldmarkup do and where can i find more info on that? google didn't give me good results...

Share this post


Link to post
Share on other sites

It's just another Inputfield to be used with processwire's form api. Instead of rendering a "real" inputfield you can just set a string (markup) to it, that will then be plainly rendered, without looking at it. What I just noticed: I was wrong above, just using it for opening and closing markup won't work as InputfieldMarkup is also wrapped in the "wrappingMarkup" that every other Inputifield does get, too.

Edit: The holy bible for working with the form api: https://processwire.com/talk/topic/2089-create-simple-forms-using-api/

Share this post


Link to post
Share on other sites

sorry for hijacking this thread, but this is for frontend forms, right? is it also possible to have some custom markup in admin forms, eg links in descriptions or such?

Share this post


Link to post
Share on other sites

Nope. This is what 90% of the backend is based on. So yeah, you can edit pretty much everything in the backend.

Share this post


Link to post
Share on other sites

but it refers to coding in the admin? i haven't done any form coding yet so that's why i have no idea ;) my question was more about if there was a kind of installable inputfield (click, click solution) with a textarea that you can then place to a template (click, click) and then it renders some markup for you.

edit: InputfieldMarkup is not that kind of a field, is it?

Share this post


Link to post
Share on other sites

i haven't done any form coding yet

Consider yourself very happy :)

  • Like 1

Share this post


Link to post
Share on other sites

InputfieldMarkup is only the inputfield, but there's no corresponding fieldtype, that you could create a field from. It's more a tool for module creation and custom backends.

Share this post


Link to post
Share on other sites

aaah, thank you - i was mixing up the wordings "inputfield" and "fieldtype" :)

  • Like 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By benbyf
      I have a a form in my site footer that can be accessed anywhere on site, I've added the form in the _inc.php file and added the render in the pages footer.php. However, this works well on the homepage e.g. you can submit said form and get a thank you on reload, doesnt work at all on other pages... Just lots like a fresh reload. Any thing im doing wrong here or ways to diagnose as there isn't an error log for formbuilder etc...?
    • By Peter Knight
      I have a few web forms which require testing on a weekly basis and I don't want the recipients (administrators) to receive these test emails.
      What would be a good way to test approx 15 forms from the front end and have the test delivered a list of secondary administrator recipients?
      I'm thinking that I could have some kind of config file which watches for a trigger word or email and then understands that it's a test and to bypass the normal admins?
      All of the forms ask for an email address so I could setup an email such as 'testform@email.not' etc which my config file (hook?) would watch for.
      Or is there a better way to do this?
      Additionally, I have a few extra requirements...
      Forms should goto an alternative success page. This is because I don't want my test to skew my Google Analytics conversion tracking Forms would need to be tested from the front-end and not the PW admin area Any advice appreciated.
      BTW I realise this should be posted in the proper FormBuilder support forum. I am in the process of renewing my license for access to that support forum.
       
    • By J_Szwarga
      What is the best practice for having a form (only accessible to a logged in user) save the user's progress between sections of the form? Fieldsets? Multiple forms?
      Use case: I have a very long application form that would take 30 minutes for the applicant to fill out and I would hate for all progress to be lost due to user error. The progress needs to be logged into the user's page.
      Thanks!
    • By Guy Incognito
      I'm trying to implement a front-end image upload form for user profile pictures, to a field called 'profile_picture'. The code is based on the various examples found around these forums but isn't yet 100% right.
      The form successfully submits the image to the server and updates the field in the dashboard. When you submit the firm, the page reloads and uploads the image but the template still loads the old image path (now broken path as the old image has been removed).
      I can only get the new image to show if I hit enter in the address bar forcing the page to reload.
      Any ideas? Is it a caching issue, or something to do with the order of the script? It makes no difference if I call the image after the upload form.
      <?php //Display current user image $userImg = $user->profile_picture->first(); echo '<img src="'.$userImg->url.'">'; $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('userimage'); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if($input->post->form_submit) { if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $user->of(false); $user->profile_picture->removeAll(); // wirearray (line added by @horst: explanation is three posts beneath) $user->profile_picture = $upload_path . $files[0]; $user->save(); $user->of(true); @unlink($upload_path . $files[0]); } } ?> <form class="forum-form" accept-charset="utf-8" action="./" method="post" enctype="multipart/form-data" > <input type="file" id="attach" name="userimage" accept="image/jpg,image/jpeg,image/gif,image/png" /> <input type="submit" name="form_submit" value="Submit"/> </form>
       
    • By Kiwi Chris
      Forms are an essential part of most websites, and it's no surprise that there's an excellent premium module Form Builder but what if you're on a zero budget for whatever reason?
      It is possible to build forms quickly and easily by making use of a couple of free modules and the admin UI to give you a great deal of flexibility and speed of development, particularly if you need multiple forms on a website with different fields.
      1. First you're going to need to install a couple of modules:
      Form Template Processor
      Fieldtype Select External Option
      2. For each form that you want to display, create a template without a template file and add fields to it as you normally would. (eg I have formContact, formRegister etc)
      Tip: under the Advanced tab in the setup for each template, I add a tag Forms so that all my forms templates are nicely grouped together in admin.
      3. Create a new field of type Select External Option and call it formTemplate
      In the section Create options from any database table select
      templates as the source table id as the Option Value name as the Option Label 4. Create a new template file and call it renderForm.php (or whatever else you like)
      Add an email field to this form - This will be the email address that forms get submitted to. Add the formTemplate field you previously created to this form. This will allow you to select which of the templates you previously created such as formContact, formRegister etc you want to render. Add any other fields as usual that you want to render on the page. Add the following PHP code to the template file. $recipient = $page->email; $form = $modules->get('FormTemplateProcessor'); $form->template = $templates->get($page->formTemplate->label); // required $form->requiredFields = array('contactName', 'contactEmail', 'contactMesssage'); //Optional: This can be improved by having a field in the page template with a CSV list of required fields eg $form->requiredFields = explode(',', $page->requiredFields) $form->email = $recipient; // optional, sends form as email. FormTemplateProcessor can also save forms to the database. $content .= $form->render(); //generate the form to display. Note: this doesn't actually render the form at this point, but you have it in the $content variable ready to output wherever you want in your template.
      Add any template HTML or other PHP code and echo $content; wherever you want to render the form.
      5. Create a page using the renderForm template, and provide an email address, and select a form that you want to display.
      6. Use CSS to style the form as required.
      7. View your new page, and check that the form renders correctly.
      8. You can modify the templates you created at step 2 or create new ones as required if your requirements for what fields forms display changes.
      Note: The Form Template Processor module can also save form input as pages, and the FieldType Select External Option can be set up with filtering, so this solution can probably be refined further.
×
×
  • Create New...