Jump to content

Double quotes getting added in page Title via API save


Jo J
 Share

Recommended Posts

Using the ff snippet I derived from one kind member here (sorry, I can't remember & I also cleared my browser cache), I cannot figure out how to avoid double quote enclosures on titles with commas that are being added in the admin:


while($row = $files->getCSV('importwines.csv',['separator' => '|'])) {

    $title = wire('sanitizer')->selectorValue($row['title']);
    $title = wire("sanitizer")->text($title, array("maxLength"=>128));  // fetch and sanitize the title
    $p = wire('pages')->get("title={$title}");                   // check if it already exists
    if(0 < $p->id) continue;                                            // move on to the next record if it exists
    $p = new Page();
    $p->template = "wine-item";
    $p->parent = "wine-list";
    $p->title = $title;                                                 // use the sanitized title
    $p->vintage = wire("sanitizer")->int($row['vintage']);
    $p->price = wire("sanitizer")->float($row['price']);
    $p->category = wire("sanitizer")->int($row['category']);
    $p->location = wire("sanitizer")->text($row['location'], array("maxLength"=>128));
    $p->of(false);
    $p->save();
}

 

These are the escape characters i've tried:

"vintage"|"title"|"price"|"location"|"category"
2020|"Cross Barn Chardonnay\\, Sonoma Coast"|105.00|"United States"|1324
2020|Truchard Chardonnay, Carneros|115.00|"United States"|1324
2018|"""Grgich Chardonnay, Napa Valley"""|170.00|"United States"|1324

 

Undesired results as page titles in the admin includes the double quotes:

"Cross Barn Chardonnay , Sonoma Coast"
"Truchard Chardonnay, Carneros"
"Grgich Chardonnay, Napa Valley"

 

These 3 are also being excluded by a broad $page->find($selector) selector filter unless I manually delete the double quotes in the admin.

I think the $sanitizer->selectorValue() above also calls the new selectorValueV1() & selectorValueV2() because I am using PW3.0.210.

Is there another sanitizer I should be using for the title?

Link to comment
Share on other sites

I ought to have known better. It's not a title issue, rather it's the name--that I should be validating for existence. (And the sanitizer->selectorValue doesn't help either.

So, here's what worked:

--same-- 	
	$title = $row['title'];
    $name = wire('sanitizer')->name($title,true,128,'-');
    $p = wire('pages')->get("name={$name}");                            // check if name already exists
    if(0 < $p->id) {
        continue;
    }
--same--

Is there a better answer?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...