Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:44:27+00:00 2026-06-12T14:44:27+00:00

I have a form where an XML file is uploaded. After the form is

  • 0

I have a form where an XML file is uploaded. After the form is submitted I have to check the content of a pair of tags in the XML file. If the content of the tags is different from some expected, an error should be shown next to the form.

I don’t know exactly how to organize this code, any help?

tags: prevalidation, postvalidation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:44:28+00:00Added an answer on June 12, 2026 at 2:44 pm

    You have several places to perform this check:

    • in the action that create the form
    • in the form using a custom validator
    • in the model class (wich isn’t really recommended …)

    I prefer the custom validator because if you have to re-use the form somewhere else you won’t have to re-implement the logic of checking the xml.

    So in your sfForm class, add a custom validator to your file widget:

    class MyForm extends sfForm
    {
      public function configure()
      {
        // .. other widget / validator configuration
    
        $this->validatorSchema['file'] = new customXmlFileValidator(array(
          'required'  => true,
        ));
    

    And inside your new validator at /lib/validator/customXmlFileValidator.class.php:

    // you extend sfValidatorFile, so you keep the basic file validator
    class customXmlFileValidator extends sfValidatorFile
    {
      protected function configure($options = array(), $messages = array())
      {
        parent::configure($options, $messages);
    
        // define a custom message for the xml validation
        $this->addMessage('xml_invalid', 'The XML is not valid');
      }
    
      protected function doClean($value)
      {
        // it returns a sfValidatedFile object
        $value = parent::doClean($value);
    
        // load xml file
        $doc = new DOMDocument();
        $doc->load($this->getTempName());
    
        // do what ever you want with the dom to validate your xml
        $xpath = new DOMXPath($doc);
        $xpath->query('/my/xpath');
    
        // if validation failed, throw an error
        if (true !== $result)
        {
          throw new sfValidatorError($this, 'xml_invalid');
        }
    
        // otherwise return the sfValidatedFile object from the extended class
        return $value;
      }
    }
    

    Do not forget to clear your cache php symfony cc and it should be ok.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using c# .net , windows form application. I have a XML file which
I am generating a rss(xml) output form a php file. I have got a
I currently have a datasource from a client in the form of XML, this
I have a .xslt that translates xml from one form to another (I'm not
I am trying to auto increment my xml file. I have a form that
I have a C# ASP.NET web page with an xml file upload form. When
I have dynamically created a xml string form a JSON object returned from server.
So I have a task of reading from an xml file which contains a
I have this form to upload an xml file to server, I am using
So, I have perform two steps a) Create a some random xml file in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.